Connect External Model APIs to Claude Code Easily

Learn how to set up an API key for Claude Code and integrate external LLM services. Using the Kimi API as an example, this guide shows how to connect a third-party model and apply it in real coding scenarios.

10 min readUpdated: 2026-09-28
Connect Kimi API to Claude Code Easily

Integrating different AI models into development workflows often requires additional configuration and compatibility setup. Claude Code provides a practical way to connect external models and enhance coding workflows with powerful AI capabilities. This guide explains how to set up the integration, streamline communication, and use the API effectively for faster and more efficient development.

What is Claude Code and how does it work?

Claude Code is an AI-powered coding tool designed to help developers write, understand, and manage code more efficiently. It works by using advanced AI models to analyze projects, suggest solutions, automate coding tasks, and assist with debugging directly from the development environment. With Claude Code API integration, developers can connect AI capabilities with external applications and customize workflows.

Why use external AI models in the Claude Code?

Claude Code already provides powerful AI capabilities, but developers may connect external AI models to meet specific needs such as cost control, model flexibility, and compatibility with existing workflows. This allows teams to use Claude Code with the models and infrastructure that best fit their projects. Here are some benefits of using external AI models with Claude Code.

  • Better cost control

External AI models give teams more flexibility in managing AI usage costs. Developers can choose suitable models, optimize API usage, and reduce unnecessary expenses when running large-scale or long-term coding workflows.

  • Direct data integration

External integrations allow Claude Code to pull information directly from third-party services. This reduces manual work and helps developers create smoother workflows using the Claude Code API.

  • Workflow automation and tool interoperability

External AI models enable Claude Code to perform tasks like triggering workflows, updating tickets, and connecting with APIs or databases. This helps automate repetitive development processes and improves productivity.

  • Extensible and enterprise-ready architecture

Claude Code supports flexible integrations with multiple AI providers and external frameworks. Organizations can create secure, scalable workflows while managing Claude Code API usage more effectively.

How to connect an external LLM API to Claude Code?

Connecting external LLM APIs with Claude Code allows developers to access additional AI models and create more flexible development workflows. The process typically involves configuring an API connection, adding authentication details, and defining how the external service communicates with Claude Code.

For example, developers can connect the Kimi API to Claude Code through an API key, enabling them to use Kimi models within their coding environment and customize AI-assisted workflows based on their project needs.

Integrate the Kimi API into the Claude Code

Integrating the Kimi API with Claude Code allows developers to leverage the Kimi K3 model’s advanced code and agent capabilities directly in their development environment. Here’s a step-by-step overview of how to use the Claude Code API effectively.

Obtain Your API Key

Visit Kimi open platform and create an API key. The full key is shown only once — copy it before leaving the page and store it in a password manager or secret manager.

Note: The Kimi API is a paid, pay-as-you-go service. Make sure your account has available balance before your first call — check or top up under Billing in the console. A new API key alone does not enable calls if the account balance is zero.

Get the Kimi API Key from the console

Install Claude Code

Skip this step if Claude Code is already installed. Use the native installer (recommended by Anthropic):

macOS and Linux:

curl -fsSL https://claude.ai/install.sh | bash

Windows (PowerShell):

irm https://claude.ai/install.ps1 | iex

If the install script is unreachable from your network (for example, it returns a 403 error), use the npm method below instead.

You can also install it as a global npm package (requires Node.js 22 or later):

npm install -g @anthropic-ai/claude-code

If you need to install Node.js first:

macOS and Linux:

# Install Node.js curl -fsSL https://fnm.vercel.app/install | bash # Open a new terminal so fnm takes effect fnm install 24.3.0 fnm default 24.3.0 fnm use 24.3.0

Open a new terminal before continuing (or run eval "$(fnm env)" in the current one) — otherwise fnm install fails with "We can't find the necessary environment variables".

Windows (PowerShell):

# Right-click the Windows button, click "Terminal", then run: winget install OpenJS.NodeJS Set-ExecutionPolicy -Scope CurrentUser RemoteSigned # Close the terminal window and open a new one

After installing Node.js, run the initialization once. It marks the first-run onboarding as complete so Claude Code starts directly:

node --eval " const fs = require('fs'); const path = require('path'); const os = require('os'); const homeDir = os.homedir(); const filePath = path.join(homeDir, '.claude.json'); if (fs.existsSync(filePath)) { const content = JSON.parse(fs.readFileSync(filePath, 'utf-8')); fs.writeFileSync(filePath, JSON.stringify(Object.assign({}, content, { hasCompletedOnboarding: true }), null, 2), 'utf-8'); } else { fs.writeFileSync(filePath, JSON.stringify({ hasCompletedOnboarding: true }, null, 2), 'utf-8'); }"

Not a first-time install? Clean up legacy config first

If you previously modified ~/.claude/settings.json with third-party tools or by hand, stale values left in its env field override environment variables exported in your terminal, so the new configuration may not take effect or model requests may be silently rewritten. Run this cleanup script first:

node --eval " const fs = require('fs'); const path = require('path'); const os = require('os'); const settingsPath = path.join(os.homedir(), '.claude', 'settings.json'); if (fs.existsSync(settingsPath)) { const content = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')); if (content && typeof content === 'object' && content.env && typeof content.env === 'object') { for (const key of [ 'ANTHROPIC_BASE_URL', 'ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL', 'ANTHROPIC_SMALL_FAST_MODEL', 'CLAUDE_CODE_SUBAGENT_MODEL', 'ANTHROPIC_DEFAULT_OPUS_MODEL', 'ANTHROPIC_DEFAULT_OPUS_MODEL_NAME', 'ANTHROPIC_DEFAULT_SONNET_MODEL', 'ANTHROPIC_DEFAULT_SONNET_MODEL_NAME', 'ANTHROPIC_DEFAULT_HAIKU_MODEL', 'ANTHROPIC_DEFAULT_HAIKU_MODEL_NAME', 'ANTHROPIC_DEFAULT_FABLE_MODEL', 'ANTHROPIC_DEFAULT_FABLE_MODEL_NAME', 'ENABLE_TOOL_SEARCH', 'CLAUDE_CODE_AUTO_COMPACT_WINDOW', 'CLAUDE_CODE_EFFORT_LEVEL', ]) { delete content.env[key]; } fs.writeFileSync(settingsPath, JSON.stringify(content, null, 2), 'utf-8'); } }"

The script only removes endpoint, credential, and model-related variables from env; it does not touch other settings in settings.json (permissions, theme, and so on).

Also check shell config files such as ~/.zshrc and ~/.bashrc for stale ANTHROPIC_* exports (Windows users: check user environment variables) and delete them, otherwise they will interfere with the new configuration.

Configure Kimi in Claude Code settings

Write the following variables into the env field of ~/.claude/settings.json, then restart Claude Code for them to take effect. This example sets the HAIKU tier to kimi-k2.7-code and all other tiers to kimi-k3[1m]. On Windows, this file is at %USERPROFILE%\.claude\settings.json.

{ "env": { "ANTHROPIC_BASE_URL": "https://api.moonshot.ai/anthropic", "ANTHROPIC_AUTH_TOKEN": "YOUR_MOONSHOT_API_KEY", "ANTHROPIC_MODEL": "kimi-k3[1m]", "ANTHROPIC_DEFAULT_OPUS_MODEL": "kimi-k3[1m]", "ANTHROPIC_DEFAULT_SONNET_MODEL": "kimi-k3[1m]", "ANTHROPIC_DEFAULT_HAIKU_MODEL": "kimi-k2.7-code", "ANTHROPIC_DEFAULT_FABLE_MODEL": "kimi-k3[1m]", "CLAUDE_CODE_SUBAGENT_MODEL": "kimi-k3[1m]", "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000", "CLAUDE_CODE_EFFORT_LEVEL": "max" } }

Replace YOUR_MOONSHOT_API_KEY with the key you copied above. If your key was created on the China platform (platform.moonshot.cn), use https://api.moonshot.cn/anthropic as the value of ANTHROPIC_BASE_URL instead.

Note: the env block in settings.json overrides same-named variables exported in your terminal. This file contains your API key in plain text; do not commit it to git.

Claude Code uses different model tiers for different scenarios (main conversation, background summarization, sub-agents, and so on). Configuring only some of the variables makes the corresponding scenarios fail silently:

VariablePurposeIf not configured
ANTHROPIC_BASE_URLKimi endpoint addressRequests go to Anthropic's official endpoint and fail authentication
ANTHROPIC_AUTH_TOKENKimi API keyReturns 401 authentication errors
ANTHROPIC_MODELMain conversation modelModel-not-found errors
ANTHROPIC_DEFAULT_OPUS_MODEL / ANTHROPIC_DEFAULT_SONNET_MODEL / ANTHROPIC_DEFAULT_HAIKU_MODEL / ANTHROPIC_DEFAULT_FABLE_MODELModel used by each task tierTasks on the corresponding tier fail
CLAUDE_CODE_SUBAGENT_MODELSub-agent modelSub-agent tasks fail or degrade noticeably
CLAUDE_CODE_AUTO_COMPACT_WINDOWContext window that triggers auto-compactionToo small compacts early and loses context; too large causes context-length errors
CLAUDE_CODE_EFFORT_LEVELReasoning effortSet to max; lower values may reduce quality on complex tasks

Models and thinking behavior

The available Kimi models behave differently in Claude Code:

ModelThinking modeNotes
kimi-k3 (default)On by default, can be turned offWorks out of the box, no extra configuration needed
kimi-k2.7-codeForced on, cannot be turned offMust enable Thinking in Claude Code (Option+T on macOS, Alt+T on Windows/Linux) before use
kimi-k2.6OptionalGood for latency-sensitive simple tasks

With thinking off, requests to kimi-k2.7-code are rejected with 400 invalid thinking: only type=enabled is allowed for this model.

Verify the configuration

After configuring, first verify the endpoint and API key with curl:

curl https://api.moonshot.ai/anthropic/v1/messages \ --header "Authorization: Bearer YOUR_MOONSHOT_API_KEY" \ --header "Content-Type: application/json" \ --data '{"model": "kimi-k3", "max_tokens": 1, "messages": [{"role": "user", "content": "hi"}]}'

A normal JSON response means the endpoint and credential both work; a 401 means the API key is invalid or does not match the platform. Once confirmed, start Claude Code and enter /status:

  • Base URL should show https://api.moonshot.ai/anthropic

  • Model should show kimi-k3[1m]

Verify environmental variables

Claude Code's /model menu shows the models you have configured. Finally, send any message (for example hello). Receiving a normal reply confirms the end-to-end setup works.

This integration lets you fully utilize the Kimi API in Claude Code, combining real-time AI-assisted coding, automation, and multi-agent capabilities for development projects.

Benefits of using the Kimi API

Integrating the Kimi API with Claude Code unlocks powerful AI-assisted development features. Compared with using Claude Code alone, the Kimi API provides a more cost-effective option for teams that need continuous AI assistance, helping reduce API expenses while maintaining a productive development workflow.

  • Extended context understanding across large codebases

The Kimi API can analyze extensive code and project data in a single pass. This allows Claude Code to understand relationships between files, modules, and components, making large-scale projects easier to manage.

  • Faster and clearer repository analysis

Kimi quickly interprets documentation, technical notes, and repository structures. Developers can extract key insights without manually checking every file, improving Claude Code API usage for project understanding.

  • More cost-efficient AI-assisted development

The Kimi API balances high capability with cost-effectiveness. Teams can leverage AI support in Claude Code without overspending, making it a practical choice for sustained development workflows.

  • Accelerated information retrieval across projects

Kimi surfaces relevant patterns, references, and data from large codebases. This reduces search time, allowing developers to focus more on building features and improving software efficiency.

  • Smarter workflow automation and task support

The Kimi API assists with repetitive engineering tasks such as code generation and content review. By integrating it with Claude Code, teams can maintain smoother and more consistent workflows over time.

Troubleshooting

400 Bad Request while searching your local workspace

If Claude Code shows a 400 Bad Request error while searching your local workspace, the issue is often related to compatibility problems with the agent’s web or search tools. To resolve this, disable tool search functionality before launching the Claude Code CLI.

For macOS/Linux:

export ENABLE_TOOL_SEARCH=false

For Windows (PowerShell):

$env:ENABLE_TOOL_SEARCH="false"

You can also add "ENABLE_TOOL_SEARCH": "false" to the env block in settings.json to make the setting persistent.

After setting the variable, restart Claude Code and try running your workflow again. This adjustment helps prevent search-related conflicts and allows the Kimi API integration to work more smoothly.

401 authentication errors

  • Check that ANTHROPIC_AUTH_TOKEN is a valid Kimi API key, and that YOUR_MOONSHOT_API_KEY has been replaced with your key;

  • Make sure ANTHROPIC_BASE_URL matches the platform where you created the key — create the key on the platform linked in "Obtain Your API Key" above and use the endpoint shown on this page;

  • If you previously configured ANTHROPIC_API_KEY, remove it to avoid conflicts with ANTHROPIC_AUTH_TOKEN when both are present.

Model not found

Check the spelling of every model variable (kimi-k3[1m]), and make sure there are no extra spaces or quotes.

Background tasks or sub-agent errors

Usually ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_FABLE_MODEL, or CLAUDE_CODE_SUBAGENT_MODEL is not configured, so the scenario requests a model name the Kimi endpoint cannot recognize. Fill them in per the configuration reference above.

Changes do not take effect

  • Check for stale values in the env field of ~/.claude/settings.json; run the cleanup script in "Not a first-time install?" above;

  • Check shell config files such as ~/.zshrc and ~/.bashrc for stale ANTHROPIC_* exports;

  • Restart Claude Code after modifying settings.json.

Previously signed in with /login

ANTHROPIC_AUTH_TOKEN takes precedence over a saved login, so no action is usually needed. Enter /status to confirm the active credential source; run /logout to clear a saved login.

How does Claude Code support developers in their workflow?

Claude Code significantly improves development productivity by acting as an intelligent assistant that can understand, plan, and execute complex engineering tasks. It goes beyond simple code generation and becomes part of the full development lifecycle. Here is how it supports developers in their workflow.

  • End-to-end task execution

Claude Code can handle complete development tasks by analyzing your codebase, planning solutions, editing multiple files, and running build or test commands. This makes Claude Code API usage more powerful by enabling full-cycle automation instead of isolated code snippets.

  • Intelligent documentation and explanation

It works as a smart onboarding assistant for both new and legacy codebases. Claude explains functions, identifies edge cases, and helps developers understand architecture before making changes, reducing onboarding time significantly.

  • Automated testing and edge case detection

Claude Code can generate tests based on existing project patterns and identify missing test coverage. It also runs test suites and helps fix errors, improving code reliability and quality assurance.

  • Git and release management

It integrates with Git workflows to manage commits, resolve merge conflicts, and create structured pull requests. This helps teams maintain cleaner version control and smoother release cycles.

  • Tool integrations (MCP)

Through the Model Context Protocol (MCP), Claude Code connects with tools like GitHub, Jira, Slack, and Figma. This expands Claude Code API capabilities into broader development and collaboration ecosystems.

  • Dynamic workflows

For complex tasks like debugging or migrations, Claude Code can split work into subtasks and run multiple subagents. It then combines results into a unified output, improving efficiency in large-scale development projects.

Conclusion

The Claude Code API helps developers integrate powerful AI tools like the Kimi K3 into their workflows. It enables real-time context, automation, and smarter task management, improving efficiency and reducing errors. With end-to-end execution and seamless tool integration, Claude Code streamlines development. Using the Claude Code API allows teams to work faster and more confidently on complex projects.

FAQ

Yes, Claude Code supports multi-model setups through its API integration. You can connect several models, including the Kimi K3, and manage their interactions for different tasks. This flexibility makes Claude Code API usage more versatile across large projects.
Claude Code can integrate with a wide range of services such as GitHub, Jira, Slack, Figma, and custom APIs. These connections allow developers to automate workflows, sync data, and extend AI capabilities using the Claude Code API key.
Yes, you can replace or update AI models in Claude Code at any time. By updating the API key or changing the model configuration, developers can seamlessly switch to newer or different models for improved performance.
If an external API fails, Claude Code will stop the related operations and provide error feedback. Developers can retry requests, switch to backup models, or adjust settings to maintain workflow continuity using the Claude Code API.
You Might Also Like
10 Popular AI Agent Builders for Building AI Workflows
10 Popular AI Agent Builders for Building AI Workflows
2026-09-28
Trae API Integration Guide for AI Development
Trae API Integration Guide for AI Development
2026-09-28
Droid API Integration: How to Connect External AI Models
Droid API Integration: How to Connect External AI Models
2026-09-28
n8n AI Agent Guide: Build and Automate Workflows
n8n AI Agent Guide: Build and Automate Workflows
2026-09-28
Install Claude Code: Full Guide for Windows & Mac
Install Claude Code: Full Guide for Windows & Mac
2026-09-28