Skip to content

feat: api.kilo.ai/api support#5709

Open
dzianisv wants to merge 9 commits intoanomalyco:devfrom
dzianisv:kilo
Open

feat: api.kilo.ai/api support#5709
dzianisv wants to merge 9 commits intoanomalyco:devfrom
dzianisv:kilo

Conversation

@dzianisv
Copy link

Summary
Screenshot 2025-12-17 at 13 42 09

This PR adds support for Kilo Code as a new AI provider in opencode, complete with device authentication and dynamic model discovery.
Changes
Authentication (src/cli/cmd/auth.ts)

  • Added open import for browser automation
  • Implemented complete Kilo Code authentication flow using device code verification
  • Added spinner UI for better UX during auth process
  • Handles authorization approval, denial, expiration, and timeouts
  • Integrated Kilo Code as priority level 7 in provider selection
    Model Discovery (src/provider/models.ts)
  • Added Kilo Code provider configuration with Claude 3.5 Sonnet as default model
  • Implemented dynamic model discovery via Kilo Code API
  • Added local caching mechanism for models to improve performance
  • Graceful fallback to cached models if API is unavailable
  • Automatic background refresh of model list
    Provider Integration (src/provider/provider.ts)
  • Added Kilo Code provider configuration using OpenAI-compatible SDK
  • Configured proper headers and user agent for API requests
  • Added proper model merging logic with cost, limit, and options handling
    Configuration (sst.config.ts)
  • Updated SST config syntax from CommonJS to ES modules
  • Standardized import statements and semicolon usage
    Technical Details
  • Authentication: OAuth2 device code flow with 5-minute timeout
  • Model Caching: Stored in ~/.cache/opencode/kilocode-models.json
  • API Integration: Uses Kilo Code's OpenRouter-compatible endpoints
  • Error Handling: Comprehensive error handling for network issues and auth failures
    Testing
    The implementation includes proper error handling and fallback mechanisms. The device code flow supports the full OAuth2 standard with support for approval, denial, expiration, and timeout scenarios.
    Breaking Changes
    None. This is an additive feature that doesn't modify existing functionality.

dzianisv and others added 9 commits December 17, 2025 12:28
- Add JWT expiration check utility
- Implement dynamic base URL resolution based on token environment
- Add missing x-api-key and Authorization: Bearer headers
- Add organizationId to ApiAuth schema
- Add proactive token expiration warnings in CLI and model discovery
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mitalbert
Copy link

This would have been nice to have, but kilo code blocked it. They only allow on their plugins or cli, so they might block you if you try.

@abcdan
Copy link

abcdan commented Jan 28, 2026

Would be cool if they add this!

@abcdan
Copy link

abcdan commented Jan 30, 2026

I saw somewhere that Kilo added support for Moltbot. So I think it's safe to say you can use their gateway :)

@mitalbert
Copy link

I saw somewhere that Kilo added support for Moltbot. So I think it's safe to say you can use their gateway :)

Why don't you try it and let us know? Just don't use your main account.

@alexandrevilain
Copy link

alexandrevilain commented Feb 8, 2026

I reached out to the Kilo team to clarify the Kilo Gateway TOS situation. Here's their response:

Hi, Alexandre
I'm Ligia from Customer Experience. Nice to meet you.
Yes, this is a change in our terms of service, and we are now offering our gateway to be used outside Kilo Code.
Thanks!
Best,
Ligia

Kilo has also migrated their cli to an OpenCode fork, which should significantly simplify integrating the Kilo Gateway into upstream OpenCode. See: https://github.com/kilo-Org/kilo

Let me know if you need any help with the integration, @dzianisv! 👍

@micuintus
Copy link

I used a different approach by directly integrating the package from Kilo: #13863

@alexandrevilain
Copy link

Thanks @micuintus!
I also saw #13765 which looks like a great approach! It'll be interesting to see which solution the maintainers prefer 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants