K2 by Moonshot: A Cheaper Claude Code Alternative
The Chinese AI company Moonshot AI has released K2, a new giant 1T parameter open-source open weights model. Early benchmarks show impressive coding performance, with the model outperforming Claude Opus and ChatGpt 4.1.
The API access pricing is significantly cheaper than Anthropic’s pricing:
- $0.15 per million input tokens
- $2.50 per million output tokens
For me, the selling point is that the K2 model exposes an Antrhopic-compatible API, that can be used with Claude Code. As a moderate API-only user (I don't pay for any Anthropic plan), I noticed that my monthly API cost is increasing, so a comparable model for a fraction of the price is indeed very interesting for my use cases.
How to use Claude Code with K2
- Sign up at Moonshot AI and create an API key
- Add credits to your account to start using the API
- Create a bash (or fish function) to start Claude using Moonshot’s endpoint
Bash
#!/bin/bash
export ANTHROPIC_AUTH_TOKEN="sk-YOURKEY"
export ANTHROPIC_BASE_URL="https://api.moonshot.ai/anthropic"
claude "$@"
Fish shell
function kimi
set -lx ANTHROPIC_AUTH_TOKEN sk-YOURKEY
set -lx ANTHROPIC_BASE_URL https://api.moonshot.ai/anthropic
claude $argv
end
Run the script (e.g., kimi
) and use Claude as you normally would - now powered by K2.
I have tested K2 with a medium-complexity task on an existing Java/Spring Boot back-end application and it did quite well. Specifically, the task was about implementing API key access for a new set of RESTFul APIs. Before implementing the code, I have switched Claude to plan mode and created an implementation plan.
K2 added quite a lot of features, that I didn't even think of, like key auditing, IP blocking and rate limiting. It was able to correctly infer that the application uses Liquibase to generate new database schema modifications. Aside from some minor compilation errors, it did a fairly good job.
I will test K2 with front-end related tasks as well, but so far, it looks like a strong alternative to Claude Sonnet and Opus.