Kimi K2.7-Code

kimi-k2.7-code
Open sourceKimi series

Overview

262K ContextCode generationReasoningMCP

Kimi K2.7-Code is a Moonshot AI model fine-tuned specifically for coding, scoring at the top of mainstream code benchmarks including HumanEval, MBPP and BigCodeBench. It supports 70+ programming languages and the major IDE protocols, handling completion, unit tests, bug fixes and cross-file refactoring in one flow — a capable assistant for day-to-day engineering and automated code workflows.

Code completion
Speaks the major IDE completion protocols with millisecond latency and cross-file context awareness.
Code generation
Generates complete functions and classes from a natural-language description, including comments, unit tests and edge-case handling.
70+ programming languages
Native support for 70+ languages including Python, JavaScript, Go, Rust and Java.
Tool calling
Function calling and the MCP protocol connect it to code search, CI/CD and internal tooling.

Features

Tool calling
Structured output
Context caching
Batch
Web search
Streaming
Reasoning
MCP
Prefix completion
Fine-tuning

Pricing

Input¥6.5/M tokens
Input (cache hit)¥1.3/M tokens
Output¥27/M tokens

Rate Limits & Context

Context Window262K
Max Output262K
RPM (requests/min)500
TPM (tokens/min)1M

Built-in Tools

web_search
Responses API
code_interpreter
Responses API
web_extractor
Responses API

API Reference

ENDPOINT
POST https://api.tokenfab.cn/v1/chat/completions

Request Example

curl https://api.tokenfab.cn/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKENFAB_API_KEY" \
  -d '{
    "model": "kimi-k2.7-code",
    "messages": [
      {"role": "system", "content": "You are a coding assistant."},
      {"role": "user", "content": "把上面这个 Python 函数改写成 Go 语言,并补充单元测试和错误处理。"}
    ]
  }'

Response Example

JSON
{
  "id": "chatcmpl-kimi-code-9d2k7f1",
  "object": "chat.completion",
  "created": 1784950000,
  "model": "kimi-k2.7-code",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "下面是 Go 版本实现,包含单元测试和错误处理:\n\nfunc QuickSort(arr []int) ([]int, error) {\n  if len(arr) == 0 { return nil, errors.New(\"empty input\") }\n  // ... (完整代码)\n}"
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 312,
    "completion_tokens": 248,
    "total_tokens": 560
  }
}

Request Parameters

ParameterTypeRequiredDescription
modelstringModel ID, e.g. kimi-k2.7-code
messagesarrayList of chat messages, each with role and content
temperaturefloatSampling temperature, 0–2, default 0.7
top_pfloatNucleus sampling, 0–1, default 0.9
max_tokensintMaximum output tokens
streamboolWhether to stream the response, default false
toolsarrayTool definitions for function calling
tool_choicestringTool choice policy: auto / none / a named function