Kilo Gateway Provider Integration Design
Overview
This document outlines the design for integrating “Kilo Gateway” as a first-class provider in OpenClaw, modeled after the existing OpenRouter implementation. Kilo Gateway uses an OpenAI-compatible completions API with a different base URL.Design Decisions
1. Provider Naming
Recommendation:kilocode
Rationale:
- Matches the user config example provided (
kilocodeprovider key) - Consistent with existing provider naming patterns (e.g.,
openrouter,opencode,moonshot) - Short and memorable
- Avoids confusion with generic “kilo” or “gateway” terms
kilo-gateway - rejected because hyphenated names are less common in the codebase and kilocode is more concise.
2. Default Model Reference
Recommendation:kilocode/anthropic/claude-opus-4.6
Rationale:
- Based on user config example
- Claude Opus 4.5 is a capable default model
- Explicit model selection avoids reliance on auto-routing
3. Base URL Configuration
Recommendation: Hardcoded default with config override- Default Base URL:
https://api.kilo.ai/api/gateway/ - Configurable: Yes, via
models.providers.kilocode.baseUrl
4. Model Scanning
Recommendation: No dedicated model scanning endpoint initially Rationale:- Kilo Gateway proxies to OpenRouter, so models are dynamic
- Users can manually configure models in their config
- If Kilo Gateway exposes a
/modelsendpoint in the future, scanning can be added
5. Special Handling
Recommendation: Inherit OpenRouter behavior for Anthropic models Since Kilo Gateway proxies to OpenRouter, the same special handling should apply:- Cache TTL eligibility for
anthropic/*models - Extra params (cacheControlTtl) for
anthropic/*models - Transcript policy follows OpenRouter patterns
Files to Modify
Core Credential Management
1. src/commands/onboard-auth.credentials.ts
Add:
2. src/agents/model-auth.ts
Add to envMap in resolveEnvApiKey():
3. src/config/io.ts
Add to SHELL_ENV_EXPECTED_KEYS:
Config Application
4. src/commands/onboard-auth.config-core.ts
Add new functions:
Auth Choice System
5. src/commands/onboard-types.ts
Add to AuthChoice type:
OnboardOptions:
6. src/commands/auth-choice-options.ts
Add to AuthChoiceGroupId:
AUTH_CHOICE_GROUP_DEFS:
buildAuthChoiceOptions():
7. src/commands/auth-choice.preferred-provider.ts
Add mapping:
Auth Choice Application
8. src/commands/auth-choice.apply.api-providers.ts
Add import:
kilocode-api-key:
CLI Registration
9. src/cli/program/register.onboard.ts
Add CLI option:
Non-Interactive Onboarding
10. src/commands/onboard-non-interactive/local/auth-choice.ts
Add handling for kilocode-api-key:
Export Updates
11. src/commands/onboard-auth.ts
Add exports:
Special Handling (Optional)
12. src/agents/pi-embedded-runner/cache-ttl.ts
Add Kilo Gateway support for Anthropic models:
13. src/agents/transcript-policy.ts
Add Kilo Gateway handling (similar to OpenRouter):
Configuration Structure
User Config Example
Auth Profile Structure
Testing Considerations
-
Unit Tests:
- Test
setKilocodeApiKey()writes correct profile - Test
applyKilocodeConfig()sets correct defaults - Test
resolveEnvApiKey("kilocode")returns correct env var
- Test
-
Integration Tests:
- Test onboarding flow with
--auth-choice kilocode-api-key - Test non-interactive onboarding with
--kilocode-api-key - Test model selection with
kilocode/prefix
- Test onboarding flow with
-
E2E Tests:
- Test actual API calls through Kilo Gateway (live tests)
Migration Notes
- No migration needed for existing users
- New users can immediately use
kilocode-api-keyauth choice - Existing manual config with
kilocodeprovider will continue to work
Future Considerations
-
Model Catalog: If Kilo Gateway exposes a
/modelsendpoint, add scanning support similar toscanOpenRouterModels() - OAuth Support: If Kilo Gateway adds OAuth, extend the auth system accordingly
- Rate Limiting: Consider adding rate limit handling specific to Kilo Gateway if needed
-
Documentation: Add docs at
docs/providers/kilocode.mdexplaining setup and usage
Summary of Changes
| File | Change Type | Description |
|---|---|---|
src/commands/onboard-auth.credentials.ts | Add | KILOCODE_DEFAULT_MODEL_REF, setKilocodeApiKey() |
src/agents/model-auth.ts | Modify | Add kilocode to envMap |
src/config/io.ts | Modify | Add KILOCODE_API_KEY to shell env keys |
src/commands/onboard-auth.config-core.ts | Add | applyKilocodeProviderConfig(), applyKilocodeConfig() |
src/commands/onboard-types.ts | Modify | Add kilocode-api-key to AuthChoice, add kilocodeApiKey to options |
src/commands/auth-choice-options.ts | Modify | Add kilocode group and option |
src/commands/auth-choice.preferred-provider.ts | Modify | Add kilocode-api-key mapping |
src/commands/auth-choice.apply.api-providers.ts | Modify | Add kilocode-api-key handling |
src/cli/program/register.onboard.ts | Modify | Add --kilocode-api-key option |
src/commands/onboard-non-interactive/local/auth-choice.ts | Modify | Add non-interactive handling |
src/commands/onboard-auth.ts | Modify | Export new functions |
src/agents/pi-embedded-runner/cache-ttl.ts | Modify | Add kilocode support |
src/agents/transcript-policy.ts | Modify | Add kilocode Gemini handling |