# AI Gateway

> A unified API to access hundreds of AI models through a single endpoint, with built-in usage tracking, BYOK support, and organization controls.

- 网址：https://funcoding.ai/agents/kilo-code/gateway/
- 来源：Kilo Code 官方文档原文（英文），MIT 许可，同步于 2026-10-11
- 官方原文：https://kilo.ai/docs/gateway

---
The Kilo AI Gateway provides a unified, OpenAI-compatible API to access hundreds of AI models through a single endpoint at `https://api.kilo.ai/api/gateway`. It gives you the ability to track usage, manage costs, bring your own API keys, and enforce organization-level controls.

The gateway works seamlessly with the [Vercel AI SDK](https://ai-sdk.dev), the [OpenAI SDK](https://funcoding.ai/agents/kilo-code/gateway/sdks-and-frameworks/#openai-sdk), or any OpenAI-compatible client in any language.

## Key features

- **One key, hundreds of models**: Access models from Anthropic, OpenAI, Google, SpaceXAI, Mistral, MiniMax, and more with a single API key
- **OpenAI-compatible API**: Drop-in replacement for OpenAI's `/chat/completions` endpoint -- switch models by changing a single string
- **Streaming support**: Full Server-Sent Events (SSE) streaming with time-to-first-token tracking
- **BYOK (Bring Your Own Key)**: Use your own provider API keys with encrypted-at-rest storage
- **Usage tracking**: Per-request cost and token tracking with microdollar precision
- **Organization controls**: Model allow lists, provider restrictions, per-user daily spending limits, and balance management
- **Tool calling**: Robust function/tool calling with automatic repair for deduplication and orphan cleanup
- **FIM completions**: Fill-in-the-middle code completions via Mistral Codestral

```typescript
import { streamText } from "ai"
import { createOpenAI } from "@ai-sdk/openai"

const kilo = createOpenAI({
  baseURL: "https://api.kilo.ai/api/gateway",
  apiKey: process.env.KILO_API_KEY,
})

const result = streamText({
  model: kilo.chat("anthropic/claude-sonnet-4.5"),
  prompt: "Why is the sky blue?",
})
```

## Base URL

All gateway API requests use the following base URL:

```
https://api.kilo.ai/api/gateway
```

## More resources

- [Quickstart](https://funcoding.ai/agents/kilo-code/gateway/quickstart/) -- Get up and running in minutes
- [Authentication](https://funcoding.ai/agents/kilo-code/gateway/authentication/) -- API keys, sessions, and BYOK
- [Models & Providers](https://funcoding.ai/agents/kilo-code/gateway/models-and-providers/) -- Available models and routing behavior
- [Streaming](https://funcoding.ai/agents/kilo-code/gateway/streaming/) -- Real-time SSE streaming
- [API Reference](https://funcoding.ai/agents/kilo-code/gateway/api-reference/) -- Full request/response schemas
- [Usage & Billing](https://funcoding.ai/agents/kilo-code/gateway/usage-and-billing/) -- Cost tracking and organization controls
- [SDKs & Frameworks](https://funcoding.ai/agents/kilo-code/gateway/sdks-and-frameworks/) -- Integration guides for popular SDKs
