mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 14:07:20 +08:00
@opencode-ai/kilo-provider
KiloCode provider for OpenCode AI SDK. This package provides a custom AI provider that wraps the OpenRouter SDK with KiloCode-specific configuration including custom authentication, headers, and base URL.
Installation
bun install @opencode-ai/kilo-provider
Usage
Basic Usage
import { createKilo } from "@opencode-ai/kilo-provider"
const provider = createKilo({
kilocodeToken: process.env.KILOCODE_API_KEY,
})
const model = provider.languageModel("anthropic/claude-sonnet-4")
With Organization ID
const provider = createKilo({
kilocodeToken: process.env.KILOCODE_API_KEY,
kilocodeOrganizationId: "org-123",
})
Custom Base URL
const provider = createKilo({
kilocodeToken: process.env.KILOCODE_API_KEY,
baseURL: "https://custom.kilo.ai/api/",
})
With Custom Headers
const provider = createKilo({
kilocodeToken: process.env.KILOCODE_API_KEY,
headers: {
"X-Custom-Header": "value",
},
})
Configuration in OpenCode
Add the kilo provider to your .opencode/config.json:
{
"provider": {
"kilo": {
"name": "KiloCode",
"env": ["KILOCODE_API_KEY", "KILO_API_KEY"],
"api": "https://api.kilo.ai/api/openrouter/",
"npm": "@opencode-ai/kilo-provider",
"options": {
"kilocodeToken": "your-token-here",
"kilocodeOrganizationId": "org-123"
}
}
},
"model": "kilo/anthropic/claude-sonnet-4"
}
Environment Variables
The provider supports these environment variables:
KILOCODE_API_KEYorKILO_API_KEY- API authentication tokenKILOCODE_ORGANIZATION_ID- Organization ID for multi-tenant setupsKILOCODE_API_URL- Custom API base URL (defaults to https://api.kilo.ai/api/)KILOCODE_EDITOR_NAME- Custom editor name for tracking (defaults to "opencode")
Features
- ✅ KiloCode API endpoint integration
- ✅ Custom authentication via
kilocodeToken - ✅ Custom headers (X-KILOCODE-ORGANIZATIONID, X-KILOCODE-TASKID, etc.)
- ✅ Auto-loading based on authentication availability
- ✅ Anonymous mode for free models when no auth provided
- ✅ Based on OpenRouter SDK with KiloCode configuration
API
createKilo(options)
Creates a KiloCode provider instance.
Options:
kilocodeToken?: string- KiloCode authentication tokenkilocodeOrganizationId?: string- Organization ID for multi-tenant setupskilocodeModel?: string- Model ID to useopenRouterSpecificProvider?: string- Specific OpenRouter provider to usebaseURL?: string- Base URL for the KiloCode APIheaders?: Record<string, string>- Custom headers to includeapiKey?: string- API key (alternative to kilocodeToken)name?: string- Provider name for identificationfetch?: typeof fetch- Custom fetch functiontimeout?: number | false- Request timeout in milliseconds
kiloCustomLoader(provider)
Custom loader function for the kilo provider. Used internally by OpenCode's provider system.
buildKiloHeaders(metadata, options)
Build KiloCode-specific headers from metadata and options.
getEditorNameHeader()
Get editor name header value. Defaults to "opencode".
getKiloUrlFromToken(defaultUrl, token)
Parse KiloCode URL from token.
isValidKilocodeToken(token)
Validate KiloCode token format.
getApiKey(options)
Get API key from options or environment.
License
MIT