← All articles

Kimi K2.7 Code on DashScope: API Setup, HighSpeed Variant, and Routing via TheRouter

Moonshot AI's Kimi K2.7 Code and its HighSpeed variant are now available on Alibaba Cloud DashScope. We cover DashScope-specific setup, model ID differences, pricing with context cache, thinking-only mode, multimodal input, and how to route K2.7 Code through TheRouter.

· TheRouter

Moonshot AI's Kimi K2.7 Code — the 1T-parameter MoE coding specialist — landed on Alibaba Cloud DashScope (百炼) in June 2026. You can now call it through the same OpenAI-compatible endpoint you already use for Qwen models, with the same DashScope API key. The HighSpeed variant (kimi/kimi-k2.7-code-highspeed) delivers the same model at 5–6× the output speed: approximately 180 tokens/s, peaking at 260 tokens/s on short contexts.

This guide covers the DashScope-specific integration path. If you're looking for the Moonshot direct API (platform.kimi.ai), see our Kimi K2 API Integration Guide. The two paths use different API keys, different base URLs, and different model ID prefixes — mixing them up is the #1 integration error we see.

Sources: DashScope Kimi API documentation, retrieved 2026-06-23; Kimi K2.7 Code Quickstart, retrieved 2026-06-23.

DashScope vs platform.kimi.ai — What Changed

DashScope hosts third-party models alongside Alibaba's own Qwen family. When Moonshot AI deployed K2.7 Code on DashScope, it created a second access path with meaningful differences:

DashScopeKimi Direct (platform.kimi.ai)
API KeyDashScope API key from Bailian consoleMoonshot API key from platform.kimi.ai
Base URLhttps://dashscope.aliyuncs.com/compatible-mode/v1https://api.moonshot.ai/v1
Model IDkimi/kimi-k2.7-codekimi-k2.7-code
HighSpeed model IDkimi/kimi-k2.7-code-highspeedkimi-k2.7-code-highspeed
BillingThrough your Alibaba Cloud accountThrough Moonshot directly
RegionChina (Beijing)Global
Context cache20% of input price on cache hit20% of input price on cache hit
Other Kimi modelsK2.6, K2.5 also availableFull lineup including K2.6, K2.5

The DashScope path is useful if you already have a Bailian account, want unified billing across Qwen + Kimi models, or operate behind Alibaba Cloud's network. The Kimi direct path gives you global access and the full Moonshot model catalog.

Source: DashScope Kimi model page, retrieved 2026-06-23.

OpenAI-compatible means a provider exposes a chat-completions endpoint whose request and response shape matches the OpenAI API contract closely enough that an unmodified OpenAI SDK call works against it after swapping three values: API key, base URL, and model name. The minimum surface in practice is POST /v1/chat/completions with messages, model, and an OpenAI-shaped streaming response.

Getting Started — API Key and Endpoint Setup

Step 1: Activate the Kimi model on DashScope.

Go to the Bailian console model market, search for "Kimi," and click Activate Now on the Kimi model card. Confirm the authorization in the pop-up.

Step 2: Get your DashScope API key.

If you don't have one yet, follow the API key guide. Set it as an environment variable:

export DASHSCOPE_API_KEY="sk-your-dashscope-key"

Step 3: Install the OpenAI SDK.

pip install --upgrade openai

Step 4: Make your first call.

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

response = client.chat.completions.create(
    model="kimi/kimi-k2.7-code",
    messages=[{"role": "user", "content": "Write a Python function to merge two sorted lists."}],
    stream=True,
)

reasoning_content = ""
answer_content = ""
is_answering = False

for chunk in response:
    if chunk.choices:
        delta = chunk.choices[0].delta
        if hasattr(delta, "reasoning_content") and delta.reasoning_content:
            reasoning_content += delta.reasoning_content
        if hasattr(delta, "content") and delta.content:
            if not is_answering:
                is_answering = True
            answer_content += delta.content
            print(delta.content, end="", flush=True)

Note the model ID uses the kimi/ prefix — this is required on DashScope. On the Moonshot direct API you'd use kimi-k2.7-code without the prefix.

Source: DashScope Kimi API call examples, retrieved 2026-06-23.

Standard vs HighSpeed — When to Use Which

DashScope offers two K2.7 Code model IDs:

Model IDOutput SpeedInput Price (per 1M tokens)Output Price (per 1M tokens)Cache Hit Price
kimi/kimi-k2.7-codeStandard$0.95$4.0020% of input ($0.19)
kimi/kimi-k2.7-code-highspeed~180 tok/s (up to 260)$1.90$8.0020% of input ($0.38)

Both model IDs run the exact same model — HighSpeed trades higher per-token cost for dramatically faster output. The use cases split cleanly:

  • Use HighSpeed for interactive coding assistants, IDE integrations, and any flow where a human is waiting for the response. The 5–6× speedup materially improves the developer experience.
  • Use Standard for batch code review, automated test generation, CI/CD pipelines, and any non-interactive workload where latency doesn't matter but cost does.

Both variants are thinking-only models: enable_thinking is always true and cannot be set to false. The model always outputs reasoning_content before the main response. Factor thinking tokens into your cost estimate — they're billed as output tokens.

Sources: Kimi K2.7 Code Pricing, retrieved 2026-06-23; DashScope Kimi API, retrieved 2026-06-23.

Code Examples

Python — Streaming with Thinking

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi/kimi-k2.7-code-highspeed",
    messages=[
        {"role": "system", "content": "You are a senior software engineer."},
        {"role": "user", "content": "Refactor this function to use async/await:\n\ndef fetch_data(urls):\n    results = []\n    for url in urls:\n        resp = requests.get(url)\n        results.append(resp.json())\n    return results"},
    ],
    stream=True,
)

reasoning = ""
answer = ""
is_answering = False

for chunk in completion:
    if not chunk.choices:
        continue
    delta = chunk.choices[0].delta
    if hasattr(delta, "reasoning_content") and delta.reasoning_content:
        if not is_answering:
            print(delta.reasoning_content, end="", flush=True)
        reasoning += delta.reasoning_content
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n\n--- Response ---\n")
            is_answering = True
        print(delta.content, end="", flush=True)
        answer += delta.content

Node.js — Non-Streaming

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.DASHSCOPE_API_KEY,
  baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1",
});

const response = await client.chat.completions.create({
  model: "kimi/kimi-k2.7-code",
  messages: [
    { role: "user", content: "Write a TypeScript generic function for retry with exponential backoff." },
  ],
  enable_thinking: true,
});

const msg = response.choices[0].message;
if (msg.reasoning_content) {
  console.log("Thinking:", msg.reasoning_content.slice(0, 200), "...");
}
console.log("Answer:", msg.content);

cURL — Quick Test

curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi/kimi-k2.7-code-highspeed",
    "messages": [
      {"role": "user", "content": "Explain the difference between mutex and semaphore with Go examples."}
    ],
    "enable_thinking": true,
    "stream": true
  }'

Note that enable_thinking is not a standard OpenAI parameter. In the Python SDK, pass it via extra_body={"enable_thinking": True} for non-streaming calls. In the Node.js SDK, pass it as a top-level parameter. In cURL/HTTP, include it in the JSON body directly.

Source: DashScope Kimi API call examples, retrieved 2026-06-23.

Multimodal Input — Vision and Video

K2.7 Code on DashScope supports image and video input alongside text. This is useful for coding tasks that involve UI screenshots, architecture diagrams, or recorded walkthroughs.

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="kimi/kimi-k2.7-code",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Generate the HTML/CSS to replicate this UI component."},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/screenshot.png"
                    },
                },
            ],
        }
    ],
    extra_body={"enable_thinking": True},
)

print(completion.choices[0].message.content)

Limitations on DashScope: Images and videos must be provided via public URL — Base64 encoding is not supported. Image resolution should stay below 4K (4096×2160). Video files support MP4, MOV, AVI, WEBM, and others, with a 100 MB total request size limit.

Source: DashScope Kimi multimodal docs, retrieved 2026-06-23.

Pricing Comparison — DashScope vs Kimi Direct

K2.7 Code (Standard)K2.7 Code HighSpeed
Kimi Direct input / output (per 1M)$0.95 / $4.00$1.90 / $8.00
DashScope input / output (per 1M)Same pricing tierSame pricing tier
Cache hit discount20% of input price20% of input price
Billing currencyUSD (Moonshot)RMB (Alibaba Cloud)

Pricing parity means the choice between DashScope and Kimi direct comes down to billing consolidation, not cost arbitrage. If you already run Qwen models through DashScope, adding K2.7 Code costs nothing extra in integration effort — same API key, same endpoint, different model ID.

Context cache reduces repeat-context costs significantly. For multi-turn coding conversations where the system prompt and prior turns are cached, input tokens can drop to $0.19/M (standard) or $0.38/M (HighSpeed).

Sources: Kimi K2.7 Code Pricing, retrieved 2026-06-23; DashScope Kimi API cache note, retrieved 2026-06-23.

Routing K2.7 Code Through TheRouter

TheRouter routes OpenAI-compatible requests through configured providers. To route K2.7 Code requests through DashScope as the backend:

  1. Configure DashScope as a provider in your TheRouter setup with the DashScope base URL and API key.
  2. Map the model ID moonshot/kimi-k2.7-code to the DashScope model ID kimi/kimi-k2.7-code.
  3. Set up fallback routing — for example, fall back from DashScope to the Kimi direct API if DashScope is unavailable.

TheRouter's model fallback feature lets you chain providers: try DashScope first (lower latency from within Alibaba Cloud), fall back to Kimi direct, then optionally to another coding model like DeepSeek V4 or GLM-5.2.

For teams already using TheRouter with Aliyun Bailian, K2.7 Code slots into the existing provider configuration with a single model mapping addition.

Source: TheRouter model fallback guide.

Common Errors and Fixes

InvalidModelId: model kimi-k2.7-code not found

You're missing the kimi/ prefix. On DashScope's OpenAI-compatible endpoint, use kimi/kimi-k2.7-code, not kimi-k2.7-code.

AuthenticationError: Incorrect API key

You're using a Moonshot API key with the DashScope endpoint (or vice versa). DashScope keys start with sk- and are obtained from the Bailian console. Moonshot keys come from platform.kimi.ai.

enable_thinking cannot be set to false

K2.7 Code is a thinking-only model. Remove enable_thinking: false from your request. The parameter is always implicitly true.

Base64 image not supported

DashScope's Kimi multimodal endpoint only accepts image/video via public URL. Upload your files to OSS or any CDN first, then pass the URL.

RegionNotAvailable

Kimi models on DashScope are currently available in the China (Beijing) region only. Ensure your API key is from the Beijing region and your base URL points to dashscope.aliyuncs.com.

Thinking tokens inflating cost

K2.7 Code always produces thinking tokens (billed as output). For cost control, monitor reasoning_content length. If thinking tokens consistently exceed the response, consider whether the task actually needs deep reasoning — simpler tasks may be more cost-effective on K2.6 with thinking disabled.

Source: DashScope Kimi getting started, retrieved 2026-06-23.

Production Checklist

  • API key isolation: Use a separate DashScope API key for production vs. development.
  • Model ID prefix: Confirm kimi/kimi-k2.7-code (not kimi-k2.7-code) in your DashScope config.
  • Streaming enabled: K2.7 Code produces long thinking chains — stream to avoid timeouts.
  • Thinking token budget: Monitor reasoning_content length; set max_tokens to cap total output including thinking.
  • Context cache utilization: Keep system prompts and static context at the beginning of the message array to maximize cache hits (20% input cost).
  • Fallback configured: Route through TheRouter with DashScope → Kimi direct → alternative model fallback chain.
  • Region lock acknowledged: DashScope Kimi is Beijing-region only; plan network paths accordingly.
  • Legacy model migration: K2, K2-Instruct, and K2-Thinking are scheduled for sunset on July 9, 2026 on DashScope. Migrate to K2.7 Code or K2.6.
  • Rate limits tested: Verify your DashScope tier's RPM/TPM limits handle your expected K2.7 Code traffic.
  • Error handling: Implement retry logic for 429 (rate limit) and 503 (capacity) responses.

FAQ

Can I use K2.7 Code HighSpeed for the same tasks as the standard variant?

Yes. HighSpeed runs the identical model — same weights, same capabilities. The only difference is inference speed (5–6× faster) and price (2× higher). Pick based on whether your use case is latency-sensitive.

Does K2.7 Code on DashScope support tool calls (function calling)?

Yes. K2.7 Code supports OpenAI-compatible function calling on both DashScope and Kimi direct. Pass your tool definitions in the tools parameter as you would with any OpenAI-compatible model.

Is K2.7 Code available in DashScope regions outside Beijing?

Not currently. Kimi models on DashScope are deployed in the China (Beijing) region only. For global access, use the Kimi direct API at api.moonshot.ai.

How does K2.7 Code compare to DeepSeek V4 for coding tasks?

We covered this in depth in our Coding Agent Model Routing Comparison. Short version: K2.7 Code excels at long-horizon multi-file tasks with 30% fewer reasoning tokens; DeepSeek V4 offers broader general-purpose strength at a lower price point.

What happens to existing K2.6 calls on DashScope after K2.7 Code launches?

K2.6 remains fully available and is not deprecated. K2.7 Code is an addition, not a replacement. K2.6 supports non-thinking mode (which K2.7 Code does not), making it better for tasks where you want faster, cheaper responses without the reasoning chain.

Help & contact