From 9aa0ba53bcaba355ffc947a5222c35ae3498cf11 Mon Sep 17 00:00:00 2001 From: aiapienthusiast <327629069+aiapienthusiast@users.noreply.github.com> Date: Wed, 14 Oct 2026 17:47:27 +0400 Subject: [PATCH] feat(llm): add Cheaper Inference provider support --- README.md | 2 +- docs/content/docs/(configuration)/config.mdx | 5 +- .../docs/(getting-started)/quickstart.mdx | 1 + interface/src/api/schema.d.ts | 1 + interface/src/components/ModelSelect.tsx | 2 + .../src/components/settings/constants.ts | 7 +++ interface/src/lib/providerIcons.tsx | 19 +++++++ src/api/models.rs | 3 ++ src/api/providers.rs | 10 ++++ src/config.rs | 13 +++++ src/config/load.rs | 54 +++++++++++++++---- src/config/onboarding.rs | 6 +++ src/config/providers.rs | 11 ++++ src/config/toml_schema.rs | 3 ++ src/config/types.rs | 11 ++++ src/llm/model.rs | 1 + src/llm/routing.rs | 17 ++++++ 17 files changed, 155 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c67764041..409b77a66 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ No other agent harness is building this. It's a category. ### Prerequisites - **Rust** 1.85+ ([rustup](https://rustup.rs/)) -- An LLM API key from any supported provider (Anthropic, OpenAI, OpenRouter, Kilo Gateway, Z.ai, Groq, Together, Fireworks, DeepSeek, xAI, Mistral, NVIDIA, MiniMax, Moonshot AI, Gemini, GitHub Copilot, OpenCode Zen, OpenCode Go), or use `spacebot auth login` for Anthropic OAuth +- An LLM API key from any supported provider (Anthropic, OpenAI, OpenRouter, Kilo Gateway, Cheaper Inference, Z.ai, Groq, Together, Fireworks, DeepSeek, xAI, Mistral, NVIDIA, MiniMax, Moonshot AI, Gemini, GitHub Copilot, OpenCode Zen, OpenCode Go), or use `spacebot auth login` for Anthropic OAuth ### Build and Run diff --git a/docs/content/docs/(configuration)/config.mdx b/docs/content/docs/(configuration)/config.mdx index 15573c569..c64df6218 100644 --- a/docs/content/docs/(configuration)/config.mdx +++ b/docs/content/docs/(configuration)/config.mdx @@ -39,6 +39,7 @@ anthropic_key = "env:ANTHROPIC_API_KEY" openai_key = "env:OPENAI_API_KEY" openrouter_key = "env:OPENROUTER_API_KEY" kilo_key = "env:KILO_API_KEY" +cheaperinference_key = "env:CHEAPERINFERENCE_API_KEY" zhipu_key = "env:ZHIPU_API_KEY" groq_key = "env:GROQ_API_KEY" together_key = "env:TOGETHER_API_KEY" @@ -252,7 +253,7 @@ groq_key = "gsk_abc123..." The `secret:` prefix resolves from the agent's secret store at config load time. If the secret doesn't exist, the value is treated as missing and implicit env fallbacks are tried. -LLM keys also have implicit env fallbacks — if no key is set in the TOML, Spacebot checks `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `OPENROUTER_API_KEY`, `KILO_API_KEY`, and `OPENCODE_GO_API_KEY` automatically. +LLM keys also have implicit env fallbacks — if no key is set in the TOML, Spacebot checks `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `OPENROUTER_API_KEY`, `KILO_API_KEY`, `CHEAPERINFERENCE_API_KEY`, and `OPENCODE_GO_API_KEY` automatically. Use `POST /api/secrets/migrate` to automatically move plaintext credentials from `config.toml` into the secret store and replace them with `secret:` references. See [Secret Store -- Migration](/docs/secrets#migration) for details. @@ -290,6 +291,7 @@ Model names include the provider as a prefix: | OpenAI | `openai/` | `openai/gpt-4o` | | OpenRouter | `openrouter//` | `openrouter/anthropic/claude-sonnet-4-20250514` | | Kilo Gateway | `kilo//` | `kilo/anthropic/claude-sonnet-4.5` | +| Cheaper Inference | `cheaperinference/` | `cheaperinference/gpt-5.4-mini` | | Custom provider | `/` | `my_openai/gpt-4o-mini` | You can mix providers across process types. See [Routing](/docs/routing) for the full routing system. @@ -413,6 +415,7 @@ If you define a custom provider with the same ID as a legacy key, your custom co | `openai_key` | string | None | OpenAI API key (`secret:NAME`, `env:VAR_NAME`, or literal) | | `openrouter_key` | string | None | OpenRouter API key (`secret:NAME`, `env:VAR_NAME`, or literal) | | `kilo_key` | string | None | Kilo Gateway API key (`secret:NAME`, `env:VAR_NAME`, or literal) | +| `cheaperinference_key` | string | None | Cheaper Inference API key (`secret:NAME`, `env:VAR_NAME`, or literal) | | `zhipu_key` | string | None | Zhipu AI (GLM) API key (`secret:NAME`, `env:VAR_NAME`, or literal) | | `groq_key` | string | None | Groq API key (`secret:NAME`, `env:VAR_NAME`, or literal) | | `together_key` | string | None | Together AI API key (`secret:NAME`, `env:VAR_NAME`, or literal) | diff --git a/docs/content/docs/(getting-started)/quickstart.mdx b/docs/content/docs/(getting-started)/quickstart.mdx index 91f6bee5f..e0c80114a 100644 --- a/docs/content/docs/(getting-started)/quickstart.mdx +++ b/docs/content/docs/(getting-started)/quickstart.mdx @@ -95,6 +95,7 @@ Create `~/.spacebot/config.toml`: anthropic_key = "sk-ant-..." # or: openrouter_key = "sk-or-..." # or: kilo_key = "sk-..." +# or: cheaperinference_key = "ci_live_..." # or: opencode_go_key = "..." # or: openai_key = "sk-..." # Keys also support env references: anthropic_key = "env:ANTHROPIC_API_KEY" diff --git a/interface/src/api/schema.d.ts b/interface/src/api/schema.d.ts index 6ad613448..196a9999e 100644 --- a/interface/src/api/schema.d.ts +++ b/interface/src/api/schema.d.ts @@ -4562,6 +4562,7 @@ export interface components { ProviderStatus: { anthropic: boolean; azure: boolean; + cheaperinference: boolean; deepseek: boolean; fireworks: boolean; gemini: boolean; diff --git a/interface/src/components/ModelSelect.tsx b/interface/src/components/ModelSelect.tsx index 660d191f8..8df6aa6bf 100644 --- a/interface/src/components/ModelSelect.tsx +++ b/interface/src/components/ModelSelect.tsx @@ -16,6 +16,7 @@ const PROVIDER_LABELS: Record = { anthropic: "Anthropic", openrouter: "OpenRouter", kilo: "Kilo Gateway", + cheaperinference: "Cheaper Inference", openai: "OpenAI", "openai-chatgpt": "ChatGPT Plus (OAuth)", deepseek: "DeepSeek", @@ -132,6 +133,7 @@ export function ModelSelect({ const providerOrder = [ "openrouter", "kilo", + "cheaperinference", "anthropic", "openai", "openai-chatgpt", diff --git a/interface/src/components/settings/constants.ts b/interface/src/components/settings/constants.ts index 2c4071cbe..c69a022fd 100644 --- a/interface/src/components/settings/constants.ts +++ b/interface/src/components/settings/constants.ts @@ -101,6 +101,13 @@ export const PROVIDERS = [ placeholder: "sk-...", envVar: "KILO_API_KEY", }, + { + id: "cheaperinference", + name: "Cheaper Inference", + description: "OpenAI-compatible multi-provider gateway", + placeholder: "ci_live_...", + envVar: "CHEAPERINFERENCE_API_KEY", + }, { id: "opencode-zen", name: "OpenCode Zen", diff --git a/interface/src/lib/providerIcons.tsx b/interface/src/lib/providerIcons.tsx index f57fbb05b..809dd4813 100644 --- a/interface/src/lib/providerIcons.tsx +++ b/interface/src/lib/providerIcons.tsx @@ -111,6 +111,24 @@ function KiloIcon({ size = 24, className }: IconProps) { ); } +function CheaperInferenceIcon({ size = 24, className }: IconProps) { + return ( + + ); +} + export function ProviderIcon({ provider, className = "text-ink-faint", size = 24 }: ProviderIconProps) { const iconProps: Partial = { size, @@ -123,6 +141,7 @@ export function ProviderIcon({ provider, className = "text-ink-faint", size = 24 "openai-chatgpt": OpenAI, openrouter: OpenRouter, kilo: KiloIcon, + cheaperinference: CheaperInferenceIcon, groq: Groq, mistral: Mistral, gemini: Google, diff --git a/src/api/models.rs b/src/api/models.rs index c9457f8f8..a6e38e497 100644 --- a/src/api/models.rs +++ b/src/api/models.rs @@ -305,6 +305,9 @@ pub(super) async fn configured_providers(config_path: &std::path::Path) -> Vec<& if has_key("kilo_key", "KILO_API_KEY") { providers.push("kilo"); } + if has_key("cheaperinference_key", "CHEAPERINFERENCE_API_KEY") { + providers.push("cheaperinference"); + } if has_key("zhipu_key", "ZHIPU_API_KEY") { providers.push("zhipu"); } diff --git a/src/api/providers.rs b/src/api/providers.rs index d1981de03..8089ec16c 100644 --- a/src/api/providers.rs +++ b/src/api/providers.rs @@ -44,6 +44,7 @@ pub(super) struct ProviderStatus { openai_chatgpt: bool, openrouter: bool, kilo: bool, + cheaperinference: bool, zhipu: bool, groq: bool, together: bool, @@ -157,6 +158,7 @@ fn provider_toml_key(provider: &str) -> Option<&'static str> { "openai" => Some("openai_key"), "openrouter" => Some("openrouter_key"), "kilo" => Some("kilo_key"), + "cheaperinference" => Some("cheaperinference_key"), "zhipu" => Some("zhipu_key"), "groq" => Some("groq_key"), "together" => Some("together_key"), @@ -225,6 +227,7 @@ fn build_test_llm_config(provider: &str, credential: &str) -> crate::config::Llm openai_key: (provider == "openai").then(|| credential.to_string()), openrouter_key: (provider == "openrouter").then(|| credential.to_string()), kilo_key: (provider == "kilo").then(|| credential.to_string()), + cheaperinference_key: (provider == "cheaperinference").then(|| credential.to_string()), zhipu_key: (provider == "zhipu").then(|| credential.to_string()), groq_key: (provider == "groq").then(|| credential.to_string()), together_key: (provider == "together").then(|| credential.to_string()), @@ -506,6 +509,7 @@ pub(super) async fn get_providers( openai_chatgpt, openrouter, kilo, + cheaperinference, zhipu, groq, together, @@ -575,6 +579,7 @@ pub(super) async fn get_providers( openai_oauth_configured, has_value("openrouter_key", "OPENROUTER_API_KEY"), has_value("kilo_key", "KILO_API_KEY"), + has_value("cheaperinference_key", "CHEAPERINFERENCE_API_KEY"), has_value("zhipu_key", "ZHIPU_API_KEY"), has_value("groq_key", "GROQ_API_KEY"), has_value("together_key", "TOGETHER_API_KEY"), @@ -607,6 +612,7 @@ pub(super) async fn get_providers( openai_oauth_configured, env_set("OPENROUTER_API_KEY"), env_set("KILO_API_KEY"), + env_set("CHEAPERINFERENCE_API_KEY"), env_set("ZHIPU_API_KEY"), env_set("GROQ_API_KEY"), env_set("TOGETHER_API_KEY"), @@ -634,6 +640,7 @@ pub(super) async fn get_providers( openai_chatgpt, openrouter, kilo, + cheaperinference, zhipu, groq, together, @@ -658,6 +665,7 @@ pub(super) async fn get_providers( || providers.openai_chatgpt || providers.openrouter || providers.kilo + || providers.cheaperinference || providers.zhipu || providers.groq || providers.together @@ -695,6 +703,7 @@ pub(super) async fn get_provider_default_models() -> Json anyhow::Result> { "Moonshot AI (Kimi)", "Z.AI Coding Plan", "Kilo Gateway", + "Cheaper Inference", ]; let provider_idx = Select::new() .with_prompt("Which LLM provider do you want to use?") @@ -131,6 +132,11 @@ pub fn run_onboarding() -> anyhow::Result> { "zai-coding-plan", ), 17 => ("Kilo Gateway API key", "kilo_key", "kilo"), + 18 => ( + "Cheaper Inference API key", + "cheaperinference_key", + "cheaperinference", + ), _ => unreachable!(), }; let is_secret = provider_id != "ollama"; diff --git a/src/config/providers.rs b/src/config/providers.rs index 575b9cb2b..117688f5f 100644 --- a/src/config/providers.rs +++ b/src/config/providers.rs @@ -8,6 +8,7 @@ pub(super) const ANTHROPIC_PROVIDER_BASE_URL: &str = "https://api.anthropic.com" pub(super) const OPENAI_PROVIDER_BASE_URL: &str = "https://api.openai.com"; pub(super) const OPENROUTER_PROVIDER_BASE_URL: &str = "https://openrouter.ai/api"; pub(super) const KILO_PROVIDER_BASE_URL: &str = "https://api.kilo.ai/api/gateway"; +pub(super) const CHEAPERINFERENCE_PROVIDER_BASE_URL: &str = "https://api.cheaperinference.com"; pub(super) const OLLAMA_PROVIDER_BASE_URL: &str = "http://localhost:11434"; pub(super) const OPENCODE_ZEN_PROVIDER_BASE_URL: &str = "https://opencode.ai/zen"; pub(super) const OPENCODE_GO_PROVIDER_BASE_URL: &str = "https://opencode.ai/zen/go"; @@ -94,6 +95,16 @@ pub(crate) fn default_provider_config( api_version: None, deployment: None, }, + "cheaperinference" => ProviderConfig { + api_type: ApiType::OpenAiCompletions, + base_url: CHEAPERINFERENCE_PROVIDER_BASE_URL.to_string(), + api_key, + name: Some("Cheaper Inference".to_string()), + use_bearer_auth: false, + extra_headers: vec![], + api_version: None, + deployment: None, + }, "zhipu" => ProviderConfig { api_type: ApiType::OpenAiChatCompletions, base_url: ZHIPU_PROVIDER_BASE_URL.to_string(), diff --git a/src/config/toml_schema.rs b/src/config/toml_schema.rs index 4482428a3..ebbdf8e2d 100644 --- a/src/config/toml_schema.rs +++ b/src/config/toml_schema.rs @@ -183,6 +183,7 @@ pub(super) struct TomlLlmConfigFields { pub(super) openai_key: Option, pub(super) openrouter_key: Option, pub(super) kilo_key: Option, + pub(super) cheaperinference_key: Option, pub(super) zhipu_key: Option, pub(super) groq_key: Option, pub(super) together_key: Option, @@ -214,6 +215,7 @@ pub(super) struct TomlLlmConfig { pub(super) openai_key: Option, pub(super) openrouter_key: Option, pub(super) kilo_key: Option, + pub(super) cheaperinference_key: Option, pub(super) zhipu_key: Option, pub(super) groq_key: Option, pub(super) together_key: Option, @@ -270,6 +272,7 @@ impl<'de> Deserialize<'de> for TomlLlmConfig { openai_key: fields.openai_key, openrouter_key: fields.openrouter_key, kilo_key: fields.kilo_key, + cheaperinference_key: fields.cheaperinference_key, zhipu_key: fields.zhipu_key, groq_key: fields.groq_key, together_key: fields.together_key, diff --git a/src/config/types.rs b/src/config/types.rs index c21b837b5..66891abe5 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -365,6 +365,7 @@ pub struct LlmConfig { pub openai_key: Option, pub openrouter_key: Option, pub kilo_key: Option, + pub cheaperinference_key: Option, pub zhipu_key: Option, pub groq_key: Option, pub together_key: Option, @@ -402,6 +403,10 @@ impl std::fmt::Debug for LlmConfig { &self.openrouter_key.as_ref().map(|_| "[REDACTED]"), ) .field("kilo_key", &self.kilo_key.as_ref().map(|_| "[REDACTED]")) + .field( + "cheaperinference_key", + &self.cheaperinference_key.as_ref().map(|_| "[REDACTED]"), + ) .field("zhipu_key", &self.zhipu_key.as_ref().map(|_| "[REDACTED]")) .field("groq_key", &self.groq_key.as_ref().map(|_| "[REDACTED]")) .field( @@ -470,6 +475,7 @@ impl LlmConfig { || self.openai_key.is_some() || self.openrouter_key.is_some() || self.kilo_key.is_some() + || self.cheaperinference_key.is_some() || self.zhipu_key.is_some() || self.groq_key.is_some() || self.together_key.is_some() @@ -524,6 +530,11 @@ impl SystemSecrets for LlmConfig { secret_name: "KILO_API_KEY", instance_pattern: None, }, + SecretField { + toml_key: "cheaperinference_key", + secret_name: "CHEAPERINFERENCE_API_KEY", + instance_pattern: None, + }, SecretField { toml_key: "zhipu_key", secret_name: "ZHIPU_API_KEY", diff --git a/src/llm/model.rs b/src/llm/model.rs index 2ef0ecb40..dc368d5c4 100644 --- a/src/llm/model.rs +++ b/src/llm/model.rs @@ -4467,6 +4467,7 @@ fn provider_display_name(provider_id: &str) -> String { "openai-chatgpt" => "OpenAI ChatGPT".to_string(), "openrouter" => "OpenRouter".to_string(), "kilo" => "Kilo Gateway".to_string(), + "cheaperinference" => "Cheaper Inference".to_string(), "zhipu" => "Z.AI (GLM)".to_string(), "groq" => "Groq".to_string(), "together" => "Together".to_string(), diff --git a/src/llm/routing.rs b/src/llm/routing.rs index a4646585e..c637e1bfd 100644 --- a/src/llm/routing.rs +++ b/src/llm/routing.rs @@ -273,6 +273,22 @@ pub fn defaults_for_provider(provider: &str) -> RoutingConfig { ..RoutingConfig::default() } } + "cheaperinference" => { + let channel: String = "cheaperinference/claude-sonnet-5".into(); + let worker: String = "cheaperinference/gpt-5.4-mini".into(); + RoutingConfig { + channel: channel.clone(), + branch: channel.clone(), + worker: worker.clone(), + compactor: worker.clone(), + cortex: worker, + voice: String::new(), + task_overrides: HashMap::from([("coding".into(), channel)]), + fallbacks: HashMap::new(), + rate_limit_cooldown_secs: 60, + ..RoutingConfig::default() + } + } "openai" => { let channel: String = "openai/gpt-4.1".into(); let worker: String = "openai/gpt-4.1-mini".into(); @@ -508,6 +524,7 @@ pub fn provider_to_prefix(provider: &str) -> &str { match provider { "openrouter" => "openrouter/", "kilo" => "kilo/", + "cheaperinference" => "cheaperinference/", "openai" => "openai/", "openai-chatgpt" => "openai-chatgpt/", "anthropic" => "anthropic/",