cd /news/large-language-models/kimi-k2-api-integration-a-no-fluff-g… · home topics large-language-models article
[ARTICLE · art-101396] src=dev.to ↗ pub= topic=large-language-models verified=true sentiment=· neutral

Kimi K2 API Integration: A No-Fluff Getting Started

Moonshot AI's Kimi K2, a Mixture-of-Experts model, supports native image understanding through the standard chat-completions API, enabling multimodal tasks like document QA and screenshot analysis. The integration guide demonstrates setup via cURL and Python, covering streaming, function calling, and token management for production use.

read2 min views2 publishedAug 18, 2026

Kimi K2 is Moonshot AI's flagship Mixture-of-Experts model, and the first thing developers notice is what it can see. Unlike text-only models, K2 takes images natively through the same chat-completions interface you already know — an image_url

array inside the message content is all it takes. If your workload involves long-document QA, screenshot analysis, or an agent swarm that needs to read what's on screen, K2 is worth a serious look.

Setup is deliberately boring. You hit the standard v1 endpoint, send the same request shape used everywhere, and turn on multimodal only when you need it. This guide walks the fastest path from zero to a working request: cURL first, then Python, then the parts — function calling, error handling, token math — that tend to trip people up in production.

kimi-k2

https://api.moonshot.cn/v1

export MOONSHOT_API_KEY="sk-..."

curl https://api.moonshot.cn/v1/chat/completions \
  -H "Authorization: Bearer $MOONSHOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k2",
    "messages": [{"role": "user", "content": "Summarize the key points of this contract."}],
    "max_tokens": 1024
  }'
python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("MOONSHOT_API_KEY"),
    base_url="https://api.moonshot.cn/v1",
)

resp = client.chat.completions.create(
    model="kimi-k2",
    messages=[{"role": "user", "content": "Rewrite this error message in plain language: " + err}],
    max_tokens=512,
)
print(resp.choices[0].message.content)

The biggest difference between K2 and text-only models like DeepSeek V4 is that content

can be an array of parts:

resp = client.chat.completions.create(
    model="kimi-k2",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What is wrong with this dashboard? Be specific."},
            {"type": "image_url", "image_url": {"url": "https://example.com/dashboard.png"}},
        ],
    }],
)

Pass remote URLs or base64 data URLs. Each image consumes tokens against the 256K window, so keep images reasonably sized and crop where you can. This capability alone is why K2 often wins for document and screen-understanding tasks — for a text-only comparison, see our DeepSeek V4 guide.

stream = client.chat.completions.create(
    model="kimi-k2",
    messages=[{"role": "user", "content": "Give me 5 tips for prompt engineering."}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Define tools the usual way, then let the model emit tool_calls

:

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string"}
            },
            "required": ["city"],
        },
    },
}]

resp = client.chat.completions.create(
    model="kimi-k2",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=tools,
)
print(resp.choices[0].message.tool_calls)

Execute the tool, append the result as a tool

role message, and loop until the model finishes.

The extended Kimi K2 guide with more examples is on the taotok.io blog at https://taotok.io/kimi-k2-api-integration, and if you're deciding between K2 and DeepSeek V4, the side-by-side comparison will save you an afternoon.

── more in #large-language-models 4 stories · sorted by recency
── more on @moonshot ai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/kimi-k2-api-integrat…] indexed:0 read:2min 2026-08-18 ·