Moonshot AI(月之暗面)推出的 Kimi 系列模型,以超长上下文和卓越的文档理解能力著称。Kimi K2 支持 128K 上下文,擅长处理长文档、学术论文、代码仓库等场景。兼容 OpenAI API 格式。
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API Key 在 Moonshot 开放平台 创建。
https://api.moonshot.cn/v1
| 模型ID | 上下文 | 最大输出 | 说明 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| kimi-k2 | 128K | 8K | 最新旗舰 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-128k | 128K | 8K | 上一代旗舰 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-32k | 32K | 8K | 标准版 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-8k | 8K | 8K | 基础版 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxx",
base_url="https://api.moonshot.cn/v1"
)
response = client.chat.completions.create(
model="kimi-k2",
messages=[
{"role": "system", "content": "你是 Kimi 智能助手。"},
{"role": "user", "content": "你好!"}
],
temperature=0.7,
max_tokens=2048
)
print(response.choices[0].message.content)
curl https://api.moonshot.cn/v1/chat/completions
-H "Content-Type: application/json"
-H "Authorization: Bearer $MOONSHOT_API_KEY"
-d '{
"model": "kimi-k2",
"messages": [
{"role": "user", "content": "你好"}
]
}'
stream = client.chat.completions.create(
model="kimi-k2",
messages=[{"role": "user", "content": "解释量子纠缠"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
tools = [{
"type": "function",
"function": {
"name": "search_web",
"description": "搜索互联网",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "搜索词"}
},
"required": ["query"]
}
}
}]
response = client.chat.completions.create(
model="kimi-k2",
messages=[{"role": "user", "content": "搜索最新的AI新闻"}],
tools=tools,
tool_choice="auto"
)
Kimi 支持上传文件并在对话中引用,适合长文档分析:
# 1. 上传文件
file = client.files.create(
file=open("paper.pdf", "rb"),
purpose="file-extract"
)
# 2. 获取文件内容
file_content = client.files.content(file.id)
text = file_content.text
# 3. 在对话中使用
response = client.chat.completions.create(
model="kimi-k2",
messages=[
{"role": "system", "content": "你是文档分析助手。"},
{"role": "user", "content": f"以下是文档内容:n{text}nn请总结要点。"}
]
)
支持格式:PDF、Word、Excel、PPT、TXT、Markdown、CSV 等。
| 模型 | 输入价格 | 输出价格 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| kimi-k2 | ¥12/1M tokens | ¥36/1M tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-128k | ¥14/1M tokens | ¥42/1M tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-32k | ¥6/1M tokens | ¥18/1M tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-8k | ¥4/1M tokens | ¥12/1M tokens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 模型 | RPM | TPM | 并发 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| moonshot-v1-8k | 30 | 300,000 | 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-32k | 30 | 300,000 | 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| moonshot-v1-128k | 10 | 300,000 | 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kimi-k2 | 10 | 300,000 | 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 状态码 | 含义 | 处理 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 400 | 参数错误 | 检查请求 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 认证失败 | 检查API Key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 速率限制 | 退避重试 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 服务端错误 | 稍后重试 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
评论区