In the wave of AI-assisted development, developers are constantly looking for best practices to seamlessly integrate top-notch language models with local workflows. Anthropic introduced Claude Code As a powerful end-to-end native AI assistant, it can directly understand and manipulate the entire codebase, greatly improving development efficiency. Meanwhile, Amazon AWS' AI IDE Kiro In its free preview version, it provides access to Anthropic-specific models claude-sonnet-4-20250514 of access rights. The model achieves significant breakthroughs in coding capability, inference speed and cost-effectiveness.
In this paper, we present a clever combination of solutions: two lightweight tools developed through the community Ki2API cap (a poem) Claude Code Routerthat connects the two. The goal of this program is to allow developers to make almost no modifications to the Claude Code native experience, it's free to replace its back-end model with a more performant claude-sonnet-4-20250514The
Architecture Explained: How are workflows implemented?
The entire workflow forms a clear chain of local requests that will Claude Code The front-end interaction with the Kiro of the modeling backend is connected.
Request Path: Claude Code -> Claude Code Router -> Ki2API -> Kiro (claude-sonnet-4-20250514)

- Why do you need such an architecture?
- Standardized OpenAI interfaces:
Ki2APIplays a key adapter role. It plays a key role in the local8989port to start a service that willKiroThe model calls are encapsulated in a format that is fully compatible with the OpenAI API, including the/v1/modelscap (a poem)/v1/chat/completionspath and supports streaming responses. This makes it easy to access any client that supports the OpenAI interface. - Flexible request routing:
Claude Code Router (CCR)It is a program designed forClaude Codedesigned proxy tool. It reads the local configuration file and can intercept theClaude CodeThe different types of requests issued (e.g., regular coding, background tasks, long context processing, etc.) and forward them to the specified backend model respectively. - High availability of models:: Adoption
Kiroplatform, developers can stabilize the use ofclaude-sonnet-4-20250514Model. The model performs better and is more responsive when dealing with complex coding tasks and long process reasoning.
- Standardized OpenAI interfaces:
Three Steps to Local Configuration
Step 1: Start the Ki2API service
First, we need to start the Ki2APIIt will be used as a connection Kiro The local gateway to the platform.
git clone https://github.com/zhalice2011/ki2api
cd ki2api
docker-compose up -d
Service Default Listening http://localhost:8989The Ki2API automatically reads the local AWS SSO cache credentials (usually located in the ~/.aws/sso/cache/ directory), and has built-in automatic refresh logic. If desired, this can also be done via the KIRO_ACCESS_TOKEN cap (a poem) KIRO_REFRESH_TOKEN environment variable to manually specify credentials.
Step 2: Install Claude Code and Claude Code Router
Make sure you have the Node.jsand then through the npm global installation Claude Code cap (a poem) Claude Code RouterThe
# 如果已安装 Claude Code,可跳过此步
npm install -g @anthropic-ai/claude-code
# 安装路由工具
npm install -g @musistudio/claude-code-router
Step 3: Write the configuration file and start
establish Claude Code Router configuration file. Save the following JSON content in its entirety to the ~/.claude-code-router/config.json Path.
{
"LOG": false,
"OPENAI_API_KEY": "",
"OPENAI_BASE_URL": "",
"OPENAI_MODEL": "",
"Providers": [
{
"name": "openai",
"api_base_url": "http://localhost:8989/v1/chat/completions",
"api_key": "ki2api-key-2024",
"models": [
"claude-sonnet-4-20250514"
]
}
],
"Router": {
"default": "openai,claude-sonnet-4-20250514",
"background": "openai,claude-sonnet-4-20250514",
"think": "openai,claude-sonnet-4-20250514",
"longContext": "openai,claude-sonnet-4-20250514",
"webSearch": "openai,claude-sonnet-4-20250514"
}
}
Configuration:
Providersfield defines the available backend services. Here we willnamebecause ofopenaiThe service points to the localKi2APIThe address of theRouterThe field willClaude CodeAll task panels (default,thinkand so on) are routed to theopenaiservices andclaude-sonnet-4-20250514Model.
Once the configuration is complete, execute the following command to start Claude Code::
ccr code
At this point.CCR receivership Claude Code of the web request and follow the Router The rule forwards it to the local Ki2API service, which ultimately calls the claude-sonnet-4-20250514 Model.
Frequently Asked Questions and Solutions
- 401 Unauthorized error
- Cause analysis: The API key is incorrect or
Kiroof the access credentials have expired. - prescription:: Ensure that the configuration file
api_keytogether withKi2APIpreconfiguredki2api-key-2024Consistent. Also, checkKi2APIto confirm that it has successfully fetched or flushed the Docker container logs of theKiroThe access token for the
- Cause analysis: The API key is incorrect or
- Port conflict or connection failure
- Cause analysis: Local
8989The port is already occupied by another program, orKi2APIThe service failed to start properly. - prescription: Use
docker-compose logs -fcommand to viewKi2APIof the real-time logs to locate the problem. If there is a port conflict, you can modify thedocker-compose.ymlfile, which will8989Mapping to other available ports and synchronizing updatesCCRconfiguration file in theapi_base_urlThe
- Cause analysis: Local
- Configuration changes do not take effect
- Cause analysis:
Claude Code RouterLoad configuration at startup, runtime changes to files are not automatically reloaded. - prescription:: Modifications
config.jsonfile, you need to re-execute theccr codecommand to restart the service for the new configuration to take effect.
- Cause analysis:



































