Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #5709: feat: api.kilo.ai/api support Why it might be related: This PR appears to address Kilo support, potentially overlapping with the current PR #13765 which adds Kilo as a native provider. Both seem to be related to integrating Kilo API support, though the current PR appears to be a more comprehensive native provider implementation. Please verify if PR #5709 is a duplicate, merged, or an earlier iteration that this PR supercedes. |
|
Technically this is a backport, Kilo cli forked opencode, so we're just bringing the family back together here. |
b67b15f to
6d650ff
Compare
|
I used a different approach by directly integrating the package from Kilo: #13863 |
6d650ff to
677028b
Compare
|
@micuintus this is a good approach but it's importing 30 plus files via @kilocode/kilo-gateway. The approach above just follows github copilot enterprise syntethic database injection method, there are zero dependencies and we get dynamic model listing and we have full integration with auth flow all at around 160 lines (350 lines of tests). Kilo's gateway is openai-compatible and returns models in openrouter format so the integration is really just plumbing, not a package import. Happy to discuss further if the maintainers have a preference either way. I agree though that a plugin is not the right answer here, this is a very simple addition to opencode versus bloated and rushed npms from #13826 #13531 .. I think one of them even hardcodes models right in there.. The last thing opencode needs is this level of fragmentation.. what can be incorporated simply without adding bloat should be.. 30x vibe coded pluggins are not the solution IMO. |
|
rekram1-node this is an easy one mate. |
|
I support @Nomadcxx in this. I even made a models.dev update that's accepted for importing Kilo models, so its always flexibel and not needed to import in opencode.json as some do. See anomalyco/models.dev#928 |
|
I don't have a kilo account so I cannot test these things but Ill leave some notes. |
| opencode: "(Recommended)", | ||
| anthropic: "(Claude Max or API key)", | ||
| openai: "(ChatGPT Plus/Pro or API key)", | ||
| kilo: "(Kilo subscription)", |
There was a problem hiding this comment.
We don't want to add this as a recommended provider.
| ) : props.providerID === "kilo" ? ( | ||
| <box gap={1}> | ||
| <text fg={theme.textMuted}> | ||
| Use your Kilo subscription to access 340+ AI models through a single API key. | ||
| </text> | ||
| <text fg={theme.text}> | ||
| Get your key at <span style={{ fg: theme.primary }}>https://kilo.ai</span> | ||
| </text> | ||
| </box> |
There was a problem hiding this comment.
don't need this, dont want to add as a recommended provider.
| google: 4, | ||
| openrouter: 5, | ||
| vercel: 6, | ||
| kilo: 7, |
There was a problem hiding this comment.
don't want to add as recommended provider
| opencode: "recommended", | ||
| anthropic: "Claude Max or API key", | ||
| openai: "ChatGPT Plus/Pro or API key", | ||
| kilo: "kilo.ai subscription", |
There was a problem hiding this comment.
don't want to add as recommended provider
| if (provider === "kilo") { | ||
| prompts.log.info("Get your API key at https://kilo.ai — requires a Kilo subscription") | ||
| } |
There was a problem hiding this comment.
don't want to add as recommended provider
| async function fetchKiloModels( | ||
| apiKey: string, | ||
| ): Promise<Record<string, z.infer<typeof Model>>> { | ||
| const log = Log.create({ service: "provider.kilo" }) | ||
| const url = "https://api.kilo.ai/api/gateway/models" | ||
| try { | ||
| const response = await fetch(url, { | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| }, | ||
| signal: AbortSignal.timeout(10_000), | ||
| }) | ||
| if (!response.ok) { | ||
| log.error("Kilo models fetch failed", { | ||
| status: response.status, | ||
| }) | ||
| return {} | ||
| } | ||
| const json = (await response.json()) as { data?: KiloApiModel[] } | ||
| const models: Record<string, z.infer<typeof Model>> = {} |
There was a problem hiding this comment.
do we need this? If the models are in models.dev
Note that Im adding the dynamic model fetching this week for all the primary providers, I dont think we need this one...
| // Add Kilo provider — always visible in provider list for auth flow, | ||
| // models populated dynamically when API key is available | ||
| database["kilo"] = { | ||
| id: "kilo", | ||
| name: "Kilo", | ||
| source: "custom", | ||
| env: ["KILO_API_KEY"], | ||
| options: {}, | ||
| models: {}, | ||
| } | ||
| const kiloAuth = await Auth.get("kilo") | ||
| const kiloApiKey = | ||
| Env.get("KILO_API_KEY") ?? | ||
| (kiloAuth?.type === "api" ? kiloAuth.key : undefined) | ||
| if (kiloApiKey) { | ||
| const kiloModels = await fetchKiloModels(kiloApiKey) | ||
| if (Object.keys(kiloModels).length > 0) { | ||
| database["kilo"].models = kiloModels | ||
| } | ||
| } |
There was a problem hiding this comment.
Believe this is in models.dev
| kilo: async () => { | ||
| return { | ||
| autoload: true, | ||
| options: { | ||
| baseURL: "https://api.kilo.ai/api/gateway", | ||
| headers: { | ||
| "HTTP-Referer": "https://opencode.ai/", | ||
| "X-Title": "opencode", | ||
| }, |
|
Thanks for the review @rekram1-node makes total sense to not elevate Kilo as a recommended provider. I'll strip all the auth.ts and dialog-provider.tsx changes. On fetchKiloModels() and the database injection — the reason I added those is that models.dev currently points Kilo to npm: "opencode-kilo-auth" (the JungHoonGhae plugin). That package isn't in BUNDLED_PROVIDERS and doesn't export a standard create* function, so getSDK() falls through to BunProc.install → dynamic import → fn3 is not a function. That's the exact error @smetanokr is reporting above and I get the same error with models.dev approach just merged from @Daltonganger. The CUSTOM_LOADERS entry (which you flagged as fine) adds baseURL and headers, but it doesn't override api.npm on individual models — so the broken npm path persists. I think the cleanest fix is:
That way models.dev provides the model catalog, CUSTOM_LOADERS provides the SDK wiring, and it all works without fetchKiloModels(). If you're adding dynamic model fetching for all primary providers this week, Kilo would get that for free too. Want me to go that route? |
Add CUSTOM_LOADERS entry for Kilo gateway with: - baseURL pointing to api.kilo.ai/api/gateway - HTTP-Referer and X-Title tracking headers - autoload enabled for automatic provider registration Kilo gateway is OpenAI-compatible, serving 340+ models. Models catalog provided by models.dev. Closes anomalyco#13767
677028b to
6c654fe
Compare
|
Updated — stripped everything down to just the CUSTOM_LOADERS entry per your feedback:
The PR is now 2 files: ~12 lines in provider.ts + tests. For the models.dev side — opened anomalyco/models.dev#939 to fix the npm field from Together these two changes should make the 263 Kilo models from models.dev work in OpenCode without any custom packages. |
Nice! You were quicker than me @Nomadcxx ! Hopefully we can use Kilo quickly :) |
Ahaha I have my day planned out, want this fixed so I can finish issue with my cursor plugin and another project, it would trigger my OCD if it stayed unresolved too long ha. |

What does this PR do?
Adds Kilo as a built-in provider. Kilo's gateway is OpenAI-compatible, so this mostly wires up model discovery and auth — no new SDK needed.
The main thing: models are fetched dynamically from
api.kilo.ai/api/gateway/modelsat startup, so users don't need to manually configure models inopencode.json. Select Kilo from the provider list, enter your API key, and all available models show up.Changes:
provider.ts—fetchKiloModels()hits the Kilo models endpoint, maps pricing/capabilities/limits to opencode's schema. Kilo entry is always injected into the database (even before auth) so it appears in the provider list. Models populate once authenticated.auth.ts— Kilo in CLI auth login flow with priority and info messagedialog-provider.tsx— Kilo in TUI provider dialog with priority and descriptionprovider.test.ts— 7 tests covering dynamic model loading, error handling, and config-based setupFixes #13767
How did you verify your code works?