{"slug": "moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond", "title": "Moonshot API Complete Guide: From Kimi K2 to K3 and Beyond", "summary": "Moonshot AI has released Kimi K3, a 2.8-trillion-parameter open-weight model leading on agentic benchmarks, and its API ecosystem is now essential for AI developers. The API is OpenAI-compatible, with pricing at $3.00 per million input tokens and $15.00 per million output tokens, undercutting comparable closed models by 50-80%. International developers can access K3 via gateways like TeamoRouter to bypass Chinese credential requirements.", "body_md": "Moonshot AI has rapidly evolved from a promising Chinese AI lab into one of the most important model providers in the global market. With the release of Kimi K3 in July 2026 -- a 2.8-trillion-parameter open-weight model leading on agentic benchmarks -- understanding the Moonshot API ecosystem has become essential for any developer working with AI.\n\nThis guide covers everything you need to know: the evolution from K2 to K3, API setup and authentication, model selection, pricing, rate limits, code examples, and how to integrate Moonshot models into your application.\n\nMoonshot's model lineup has evolved through several generations. Understanding the differences helps you choose the right model for your task and budget.\n\nThe Moonshot API is OpenAI-compatible, meaning you can use the standard OpenAI Python or Node.js SDK by changing the base URL:\n\n``` python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=\"your-moonshot-api-key\",\n    base_url=\"https://api.moonshot.ai/v1\",\n)\n\nresponse = client.chat.completions.create(\n    model=\"kimi-k3\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n        {\"role\": \"user\", \"content\": \"Explain how attention mechanisms work in transformers.\"},\n    ],\n    max_tokens=4096,\n)\n\nprint(response.choices[0].message.content)\npython\n// Node.js example\nimport OpenAI from 'openai';\n\nconst client = new OpenAI({\n  apiKey: 'your-moonshot-api-key',\n  baseURL: 'https://api.moonshot.ai/v1',\n});\n\nconst response = await client.chat.completions.create({\n  model: 'kimi-k3',\n  messages: [\n    { role: 'system', content: 'You are a helpful assistant.' },\n    { role: 'user', content: 'Explain how attention mechanisms work in transformers.' },\n  ],\n  max_tokens: 4096,\n});\n\nconsole.log(response.choices[0].message.content);\n```\n\nDirect Moonshot API access requires:\n\nThese requirements create friction for international developers. If you do not have Chinese credentials, using an API gateway is the practical alternative.\n\nFor international developers, multi-provider gateways like TeamoRouter provide the simplest path to K3 access. You use the same OpenAI-compatible SDK but with the gateway's base URL and API key:\n\n``` python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=\"your-teamorouter-api-key\",\n    base_url=\"https://api.teamorouter.com/v1\",\n)\n\nresponse = client.chat.completions.create(\n    model=\"moonshotai/kimi-k3\",  # or \"kimi-k3\" depending on gateway naming\n    messages=[\n        {\"role\": \"user\", \"content\": \"Research the latest developments in fusion energy and summarize the key breakthroughs.\"},\n    ],\n)\n\nprint(response.choices[0].message.content)\n```\n\nThe gateway handles procurement, billing, and failover on the back end. You get a standard international API that works with any payment method.\n\n| Model | Input (per 1M tokens) | Output (per 1M tokens) |\n|---|---|---|\n| Kimi K3 | $3.00 | $15.00 |\n| Kimi K2.7 Code | $1.50 | $7.50 |\n| Kimi K2.6 | $1.20 | $6.00 |\n\nK3's pricing is notably aggressive for a frontier model. Comparable closed models typically charge $10-15/M input and $30-75/M output. K3 undercuts those prices by 50-80% while matching or exceeding capability on agentic benchmarks.\n\nIndependent testers have noted that K3 currently operates at a single inference level (\"max\" mode) and can consume significant output tokens, especially on complex reasoning tasks. Moonshot's claim of 21% fewer output tokens compared to K2.6 applies to the architecture but real-world usage varies. Budget accordingly -- a complex agentic task with web browsing and multi-step reasoning can easily consume 10,000-50,000 output tokens.\n\nMoonshot's API rate limits are not publicly documented in detail, but community reports suggest:\n\nFor production workloads, the reliability consideration extends beyond rate limits:\n\nThese considerations make API gateways with automatic failover particularly valuable for production use of K3, as covered in the integration patterns section below.\n\n| Use Case | Recommended Model | Reason |\n|---|---|---|\n| Autonomous web-browsing agents | K3 | #1 BrowseComp, built for multi-step web research |\n| Complex multi-file coding projects | K3 | 1M context handles large codebases; #1 Automation Bench |\n| Document-heavy analysis (legal, financial) | K3 | 1M context fits entire documents; AA-Briefcase Elo 1543 |\n| Simple single-turn coding tasks | K2.7 Code | Sufficient capability at half the price of K3 |\n| Cost-sensitive high-volume chat | K2.6 | Lowest cost; adequate for straightforward Q&A |\n| Chinese-language applications | K3 or K2.6 | All Kimi models have strong Chinese-language performance |\n| Agentic task automation | K3 | Automation Bench leader; purpose-built for multi-step execution |\n\nThe Moonshot API supports function calling (tool use) through the standard OpenAI interface:\n\n```\ntools = [\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"search_documentation\",\n            \"description\": \"Search the project documentation for relevant information\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"query\": {\n                        \"type\": \"string\",\n                        \"description\": \"The search query\"\n                    }\n                },\n                \"required\": [\"query\"]\n            }\n        }\n    }\n]\n\nresponse = client.chat.completions.create(\n    model=\"kimi-k3\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a coding assistant with access to documentation search.\"},\n        {\"role\": \"user\", \"content\": \"How do I configure Redis caching in the application?\"}\n    ],\n    tools=tools,\n    tool_choice=\"auto\",\n)\n```\n\nK3's strong tool-use performance is a key reason it leads on agentic benchmarks. The model is particularly good at deciding when to invoke tools, interpreting tool results, and chaining multiple tool calls into coherent multi-step workflows.\n\nK3 supports streaming responses through the standard `stream=True`\n\nparameter:\n\n```\nstream = client.chat.completions.create(\n    model=\"kimi-k3\",\n    messages=[{\"role\": \"user\", \"content\": \"Write a detailed analysis of quantum computing's impact on cryptography.\"}],\n    stream=True,\n)\n\nfor chunk in stream:\n    if chunk.choices[0].delta.content is not None:\n        print(chunk.choices[0].delta.content, end=\"\")\n```\n\nFor long-running agentic tasks, consider implementing a polling or callback pattern rather than holding open a streaming connection, especially given the latency variability of China-based infrastructure.\n\n```\nYour App → Moonshot API (api.moonshot.ai)\n```\n\nBest for developers with Chinese credentials who only need K3 and can tolerate occasional downtime.\n\n```\nYour App → TeamoRouter → Moonshot API (primary)\n                      → Fallback Model (if K3 is unavailable)\n```\n\nYou get K3 access without Chinese credentials, plus automatic failover and multi-model access through a single integration.\n\n```\nYour App → TeamoRouter → K3 (for research/browsing tasks)\n                      → Claude (for code generation)\n                      → GPT (for creative/general tasks)\n```\n\nRoute each task to the best model for that job. This is the pattern that maximizes performance-per-dollar across a diverse workload.\n\nMoonshot has established a pattern of rapid iteration -- K2.5, K2.6, K2.7 Code, and K3 all released within roughly 18 months. The open-weight release of K3 suggests Moonshot is committed to the open model approach, which means the community can expect:\n\nFor developers, the practical takeaway is to adopt K3 through a flexible integration layer -- an API gateway or routing platform -- so that when Moonshot releases K3.5 or K4, you can adopt it immediately without changing your application code.\n\n[TeamoRouter](https://teamorouter.com?utm_source=blog&utm_medium=seo&utm_campaign=kimi-k3) gives you instant access to Kimi K3 through a standard OpenAI-compatible API. No Chinese phone number, no Alipay, no separate accounts for every model. One API key unlocks K3 alongside Claude, GPT, Gemini, DeepSeek, and 200+ other models.\n\nStart building at [teamorouter.com](https://teamorouter.com?utm_source=blog&utm_medium=seo&utm_campaign=kimi-k3).", "url": "https://wpnews.pro/news/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond", "canonical_source": "https://dev.to/bri_whitmore_88/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond-57bm", "published_at": "2026-07-28 04:55:32+00:00", "updated_at": "2026-07-28 05:03:23.892342+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-products", "ai-tools", "ai-infrastructure"], "entities": ["Moonshot AI", "Kimi K3", "Kimi K2", "Kimi K2.7 Code", "Kimi K2.6", "TeamoRouter", "OpenAI"], "alternates": {"html": "https://wpnews.pro/news/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond", "markdown": "https://wpnews.pro/news/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond.md", "text": "https://wpnews.pro/news/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond.txt", "jsonld": "https://wpnews.pro/news/moonshot-api-complete-guide-from-kimi-k2-to-k3-and-beyond.jsonld"}}