Messages API
curl --request POST \
--url https://api.moonshot.cn/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "kimi-k3",
"messages": [
{
"role": "user",
"content": "你好"
}
],
"max_tokens": 2
}
'import requests
url = "https://api.moonshot.cn/anthropic/v1/messages"
payload = {
"model": "kimi-k3",
"messages": [
{
"role": "user",
"content": "你好"
}
],
"max_tokens": 2
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'kimi-k3', messages: [{role: 'user', content: '你好'}], max_tokens: 2})
};
fetch('https://api.moonshot.cn/anthropic/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/anthropic/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'kimi-k3',
'messages' => [
[
'role' => 'user',
'content' => '你好'
]
],
'max_tokens' => 2
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/anthropic/v1/messages"
payload := strings.NewReader("{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/anthropic/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/anthropic/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "message",
"role": "assistant",
"model": "<string>",
"content": [
{
"type": "thinking",
"thinking": "<string>",
"signature": "<string>"
}
],
"stop_reason": "end_turn",
"stop_sequence": "<string>",
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"cache_read_input_tokens": 123,
"cache_creation_input_tokens": 123,
"output_tokens_details": {
"thinking_tokens": 123
}
}
}{
"type": "error",
"error": {
"type": "<string>",
"message": "<string>"
},
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"type": "error",
"error": {
"type": "<string>",
"message": "<string>"
},
"request_id": "<string>"
}Messages API
以 Anthropic Messages API 兼容的格式调用 Kimi 模型,支持流式输出、工具调用、图片输入、思考与结构化输出。
POST
/
anthropic
/
v1
/
messages
Messages API
curl --request POST \
--url https://api.moonshot.cn/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "kimi-k3",
"messages": [
{
"role": "user",
"content": "你好"
}
],
"max_tokens": 2
}
'import requests
url = "https://api.moonshot.cn/anthropic/v1/messages"
payload = {
"model": "kimi-k3",
"messages": [
{
"role": "user",
"content": "你好"
}
],
"max_tokens": 2
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'kimi-k3', messages: [{role: 'user', content: '你好'}], max_tokens: 2})
};
fetch('https://api.moonshot.cn/anthropic/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/anthropic/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'kimi-k3',
'messages' => [
[
'role' => 'user',
'content' => '你好'
]
],
'max_tokens' => 2
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/anthropic/v1/messages"
payload := strings.NewReader("{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/anthropic/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/anthropic/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"kimi-k3\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"你好\"\n }\n ],\n \"max_tokens\": 2\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "message",
"role": "assistant",
"model": "<string>",
"content": [
{
"type": "thinking",
"thinking": "<string>",
"signature": "<string>"
}
],
"stop_reason": "end_turn",
"stop_sequence": "<string>",
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"cache_read_input_tokens": 123,
"cache_creation_input_tokens": 123,
"output_tokens_details": {
"thinking_tokens": 123
}
}
}{
"type": "error",
"error": {
"type": "<string>",
"message": "<string>"
},
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"type": "error",
"error": {
"type": "<string>",
"message": "<string>"
},
"request_id": "<string>"
}以 Anthropic Messages API 兼容的格式调用 Kimi 模型。已经在使用 Anthropic SDK、Claude Code 等工具的开发者,只需把 base URL 指向
https://api.moonshot.cn/anthropic,即可直接调用 Kimi 模型。授权
请求体
application/json
模型 ID
可用选项:
kimi-k3 对话消息列表。若最后一条为 assistant 消息,模型会从该消息内容之后继续生成(Partial Mode)。
Show child attributes
Show child attributes
本次生成的最大 Token 数,必填。达到上限而未结束时 stop_reason 为 max_tokens。
必填范围:
x >= 1系统提示,可为字符串或 text 块数组
是否以 Server-Sent Events 流式返回,默认 false
停用词,完全匹配时停止输出,匹配到的词本身不会被输出。最多 5 个,每个不超过 32 字节。
Maximum array length:
5模型可调用的工具列表
Show child attributes
Show child attributes
控制模型是否调用工具。auto(默认):模型自行决定;any:强制调用任意工具;none:不调用工具。
Show child attributes
Show child attributes
Show child attributes
Show child attributes
输出配置:推理强度与结构化输出
Show child attributes
Show child attributes
响应
消息响应
本次响应的唯一标识符
可用选项:
message 示例:
"message"
可用选项:
assistant 请求中指定的模型
内容块列表,顺序为 thinking → text → tool_use
- thinking
- text
- tool_use
Show child attributes
Show child attributes
停止原因。end_turn:自然结束(含命中 stop_sequences);max_tokens:达到 max_tokens 上限;tool_use:模型发起工具调用;refusal:触发内容安全审查。
可用选项:
end_turn, max_tokens, tool_use, refusal, null 匹配到的停用词
Token 用量
Show child attributes
Show child attributes
此页面对您有帮助吗?