models/Moonshot/Kimi-K2.7-Code
Moonshot

Kimi-K2.7-Code

text
Playground →Compare

Kimi K2.7 is a frontier-scale open-source 1T parameter model with a 262.1k context window, multi-turn tool calling, vision inputs, and structured outputs for agentic workloads.

MODALITIES
text + vision
INPUT
$0.950 /1M
OUTPUT
$4.00 /1M
CONTEXT
262K tok
MAX OUTPUT
16K tok
RELEASED
2026-06-12

Kimi-K2.7-Code (moonshot/kimi-k2.7-code) is a text model from Moonshot, released 2026-06-12. Context window: 262,144 tokens; max output 16,384. Pricing via AIgateway: input $0.950/M tokens, output $4.00/M tokens. Capabilities: tools, streaming, vision, json, reasoning. Call it via https://api.aigateway.sh/v1/chat/completions with the OpenAI SDK — set model="moonshot/kimi-k2.7-code". Best for: Chatbots, Content generation, Agentic workflows.

model · moonshot/kimi-k2.7-codefamily · Kimi

Use this model

model: moonshot/kimi-k2.7-code
curl https://api.aigateway.sh/v1/chat/completions \
  -H "Authorization: Bearer $AIGATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"moonshot/kimi-k2.7-code","messages":[{"role":"user","content":"hello"}],"stream":true}'

Capabilities

Tool callingStreamingVisionJSON modeReasoning
CONTEXT
262,144 tok
MAX OUTPUT
16,384 tok

Strengths

  • General-purpose chat
  • Long context
  • Tool use

Use cases

ChatbotsContent generationAgentic workflows

Pricing

Input$0.950 / 1M tokens
Output$4.00 / 1M tokens
You pay pass-through · 5% applied at credit top-up, not per-call.
Try in playground →CompareAPI referenceSee usage ranking →

Collections

More text models →More from MoonshotFrontier models →Free-tier models →
API schema

Call Kimi-K2.7-Code from any OpenAI SDK

POST https://api.aigateway.sh/v1/chat/completions·Content-Type: application/json·Auth: Bearer sk-aig-...
Model-specific notes
  • Returns chain-of-thought in message.reasoning_content (non-streaming) and delta.reasoning_content (streaming). Safe to display or ignore — it's separate from content.

Request body

json
{
  "model": "moonshot/kimi-k2.7-code",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user",   "content": "Hello!" }
  ],
  "temperature": 0.7,
  "top_p": 0.95,
  "max_tokens": 1024,
  "reasoning_effort": "high",   // none | low | medium | high — deeper = more thorough, more tokens
  "stream": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    }
  ],
  "tool_choice": "auto",
  "parallel_tool_calls": true,
  "response_format": { "type": "json_object" }

  // For vision: messages[].content can be an array of
  //   { type: "text", text: "..." }  and
  //   { type: "image_url", image_url: { url: "https://..." } }
}

Response

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1776947082,
  "model": "moonshot/kimi-k2.7-code",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?",
      "reasoning_content": "The user asked..."  // Kimi-K2.7-Code chain-of-thought,
        "tool_calls": [
          {
            "id": "call_abc123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\":\"Tokyo\"}"
            }
          }
        ]
      },
      "finish_reason": "stop"   // or "tool_calls" when calling a function
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 12,
    "total_tokens": 36
  }
}

Streaming (SSE) — set "stream": true

// 1. Role announcement (first chunk):
data: {"choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

// 2. Reasoning chunks (Kimi-K2.7-Code thinks first):
data: {"choices":[{"index":0,"delta":{"reasoning_content":"The user "},"finish_reason":null}]}
data: {"choices":[{"index":0,"delta":{"reasoning_content":"wants..."},"finish_reason":null}]}

// 3. Content chunks (final answer):
data: {"choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}

// Tool-call chunks (when the assistant calls a function):
data: {"choices":[{"index":0,"delta":{"tool_calls":[
  {"index":0,"id":"call_abc","type":"function",
   "function":{"name":"get_weather","arguments":""}}]},"finish_reason":null}]}
data: {"choices":[{"index":0,"delta":{"tool_calls":[
  {"index":0,"function":{"arguments":"{\"city\":"}}]},"finish_reason":null}]}
data: {"choices":[{"index":0,"delta":{"tool_calls":[
  {"index":0,"function":{"arguments":"\"Tokyo\"}"}}]},"finish_reason":null}]}
// Concat arguments fragments by index → {"city":"Tokyo"}

// Finish chunk:
data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

// Terminator:
data: [DONE]

Quickstart

# pip install aigateway-py openai
# aigateway-py adds sub-accounts, evals, replays, jobs, webhook verify.
# openai SDK covers chat — drop-in per our SDK's own guidance.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.aigateway.sh/v1",
    api_key="sk-aig-...",
)

stream = client.chat.completions.create(
    model="moonshot/kimi-k2.7-code",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

# Kimi-K2.7-Code returns chain-of-thought in message.reasoning_content —
# display it in a collapsed "show thinking" UI or just ignore it.

Errors

401authentication_errorInvalid or missing API key
402insufficient_creditsWallet empty (PAYG only)
404not_foundUnknown model or endpoint
429rate_limit_errorOver per-minute limit — see Retry-After header
500server_errorUpstream provider failed (retryable)
503service_unavailableUpstream saturated (retryable)
Full docs →API reference →OpenAPI spec →llms.txt →

Frequently asked questions

What is Kimi-K2.7-Code?
Kimi K2.7 is a frontier-scale open-source 1T parameter model with a 262.1k context window, multi-turn tool calling, vision inputs, and structured outputs for agentic workloads. It is a text model from Moonshot, accessible via AIgateway's OpenAI-compatible API at slug moonshot/kimi-k2.7-code.
How much does Kimi-K2.7-Code cost via AIgateway?
Input costs $0.950 per 1M tokens; output costs $4.00 per 1M tokens. Pass-through plus a 5% platform fee applied at top-up, not per call.
What is the context window of Kimi-K2.7-Code?
262,144 tokens. Maximum output is 16,384 tokens.
How do I call Kimi-K2.7-Code from my code?
Point the OpenAI SDK at https://api.aigateway.sh/v1 with your AIgateway key and set model to "moonshot/kimi-k2.7-code". The request and response shapes match OpenAI exactly.
Does Kimi-K2.7-Code support streaming, tool calling, vision, and JSON mode?
Streaming — yes. Tool calling — yes. Vision — yes. JSON mode — yes. Prompt caching — no.
What are the best use cases for Kimi-K2.7-Code?
Chatbots, Content generation, Agentic workflows. Key strengths: General-purpose chat; Long context; Tool use.
Can I bring my own Moonshot API key (BYOK)?
Yes. Attach a Moonshot key in your AIgateway dashboard and this model flips to pass-through — you pay Moonshot directly and AIgateway waives the 5% platform fee on those calls.