Skip to main content

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 (kilocode provider key)
  • Consistent with existing provider naming patterns (e.g., openrouter, opencode, moonshot)
  • Short and memorable
  • Avoids confusion with generic “kilo” or “gateway” terms
Alternative considered: 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
This matches the pattern used by other providers like Moonshot, Venice, and Synthetic.

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 /models endpoint 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:
Add to OnboardOptions:

6. src/commands/auth-choice-options.ts

Add to AuthChoiceGroupId:
Add to AUTH_CHOICE_GROUP_DEFS:
Add to 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:
Add handling for kilocode-api-key:
Also add tokenProvider mapping at the top of the function:

CLI Registration

9. src/cli/program/register.onboard.ts

Add CLI option:
Add to action handler:
Update auth-choice help text:

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

  1. Unit Tests:
    • Test setKilocodeApiKey() writes correct profile
    • Test applyKilocodeConfig() sets correct defaults
    • Test resolveEnvApiKey("kilocode") returns correct env var
  2. 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
  3. 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-key auth choice
  • Existing manual config with kilocode provider will continue to work

Future Considerations

  1. Model Catalog: If Kilo Gateway exposes a /models endpoint, add scanning support similar to scanOpenRouterModels()
  2. OAuth Support: If Kilo Gateway adds OAuth, extend the auth system accordingly
  3. Rate Limiting: Consider adding rate limit handling specific to Kilo Gateway if needed
  4. Documentation: Add docs at docs/providers/kilocode.md explaining setup and usage

Summary of Changes