How to Configure Multiple LLM Providers (Anthropic, OpenAI, Google GenAI, VertexAI) in Kimi Code

Use the [providers] table in your config.toml to declare each LLM endpoint with a unique name, set the type field to the corresponding protocol (anthropic, openai, google-genai, or vertexai), and map models to these providers in separate [models] tables.

Kimi Code supports simultaneous connections to multiple AI vendors through a declarative TOML configuration system. By defining several providers in a single configuration file, you can route requests to Anthropic Claude, OpenAI GPT, Google GenAI Gemini, and Vertex AI models within the same coding session. This guide explains how to structure your config.toml to configure multiple LLM providers in Kimi Code according to the official implementation in the MoonshotAI/kimi-code repository.

Understanding the Configuration Structure

Kimi Code loads provider definitions from a top-level [providers] table in your configuration file. Each provider entry requires a unique identifier name and a mandatory type field that selects the underlying protocol implementation.

The provider architecture is implemented in packages/agent-core-v2/src/kosong/provider/providerDefinition.ts, which serves as the declarative registry, while runtime registration and lookup are handled by packages/agent-core/src/session/provider-manager.ts.

When you declare a provider, you can authenticate using inline credentials or environment variables:

  • Inline credentials: Provide api_key and optional base_url directly in the provider table.
  • Environment variables: Use a [providers.<name>.env] sub-table to inject variables like GOOGLE_CLOUD_PROJECT for VertexAI.

Setting Up Four Major LLM Providers

Below is a complete configuration example that simultaneously configures Anthropic, OpenAI, Google GenAI, and VertexAI providers.

Anthropic Configuration

Define the provider with type = "anthropic" and provide your API key:

[providers.anthropic]
type = "anthropic"
api_key = "sk-ant-xxxxxxxx"

OpenAI Configuration

Specify the openai type and include your base URL and API key:

[providers.openai]
type = "openai"
base_url = "https://api.openai.com/v1"
api_key = "sk-xxxxxxxx"

Google GenAI Configuration

Use the google-genai type for Gemini models:

[providers.gemini]
type = "google-genai"
api_key = "xxxxxxxx"

VertexAI Configuration

For Google Cloud VertexAI, define the provider and set required environment variables in a sub-table:

[providers.vertexai]
type = "vertexai"

[providers.vertexai.env]
GOOGLE_CLOUD_PROJECT = "my-gcp-project"
GOOGLE_CLOUD_LOCATION = "us-central1"

Mapping Models to Providers

After declaring providers, associate specific models with them using [models."<model-id>"] tables. The provider field must match the unique name you assigned in the [providers] section.

[models."claude-opus-4-7"]
provider = "anthropic"
model = "claude-opus-4-7"

[models."gpt-4o"]
provider = "openai"
model = "gpt-4o"

[models."gemini-1.5-pro"]
provider = "gemini"
model = "gemini-1.5-pro"

[models."vertex-chat-bison"]
provider = "vertexai"
model = "chat-bison"

Kimi Code resolves these mappings at runtime through the provider manager (packages/agent-core/src/session/provider-manager.ts), automatically routing each request to the appropriate backend based on the model's assigned provider.

Managing Providers via CLI and TUI

You can modify configurations without editing TOML files manually. Kimi Code provides interactive management through:

These interfaces update the underlying config.toml while validating provider types against the registry in packages/agent-core-v2/src/kosong/provider/providerDefinition.ts.

Summary

  • Declare providers in the [providers] table with unique names and correct type values (anthropic, openai, google-genai, vertexai).
  • Authenticate using inline api_key and base_url fields, or use [providers.<name>.env] for environment-based credentials.
  • Map models to providers in [models] tables using the provider field to reference your declared names.
  • Manage interactively via the TUI (/provider) or CLI (kimi provider) rather than manual file editing.
  • Reference implementation: Provider resolution logic resides in packages/agent-core/src/session/provider-manager.ts and the definition registry is at packages/agent-core-v2/src/kosong/provider/providerDefinition.ts.

Frequently Asked Questions

Can I use the same API key for multiple provider entries?

No, each provider entry must be uniquely named, even if they share the same vendor. You can create multiple entries for the same vendor (e.g., [providers.openai-work] and [providers.openai-personal]) with different API keys or base URLs, but each requires a distinct identifier.

Why is my VertexAI provider failing to connect?

VertexAI requires Google Cloud-specific environment variables (GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION) defined in the [providers.vertexai.env] sub-table, not standard API keys. Ensure your GCP credentials are properly configured in your environment or the configuration file.

How do I switch between models from different providers during a session?

Once configured, reference the model by its ID in your commands or use the Kimi Code model selection interface. The system automatically routes requests to the correct provider based on the provider field defined in the model's configuration entry.

What happens if two providers have conflicting model names?

Kimi Code uses the model ID defined in your [models] table as the unique identifier. As long as you assign distinct TOML keys (e.g., [models."gpt-4o-openai"] vs [models."gpt-4o-azure"]), you can reference the same underlying model name from different providers without conflict.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →