curl --request POST \
--url https://api.moonshot.cn/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "kimi-k3",
"input": "<string>",
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/responses"
payload = {
"model": "kimi-k3",
"input": "<string>",
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": True
}
]
}
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',
input: '<string>',
text: {},
tools: [
{
type: 'function',
name: '<string>',
description: '<string>',
parameters: {},
strict: true
}
]
})
};
fetch('https://api.moonshot.cn/v1/responses', 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/v1/responses",
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',
'input' => '<string>',
'text' => [
],
'tools' => [
[
'type' => 'function',
'name' => '<string>',
'description' => '<string>',
'parameters' => [
],
'strict' => true
]
]
]),
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/v1/responses"
payload := strings.NewReader("{\n \"model\": \"kimi-k3\",\n \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\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/v1/responses")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"kimi-k3\",\n \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/responses")
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 \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "resp_68f0c1c2d3e4f5a6b7c8d9e0",
"object": "response",
"created_at": 123,
"completed_at": 123,
"status": "in_progress",
"model": "<string>",
"output": [
{
"type": "reasoning",
"id": "rs_68f0c1c2d3e4f5a6b7c8d9e0",
"summary": [
{
"type": "summary_text",
"text": "<string>"
}
],
"encrypted_content": "<string>",
"status": "in_progress"
}
],
"usage": {
"input_tokens": 123,
"input_tokens_details": {
"cached_tokens": 123,
"cache_write_tokens": 123
},
"output_tokens": 123,
"output_tokens_details": {
"reasoning_tokens": 123
},
"total_tokens": 123
},
"incomplete_details": {
"reason": "max_output_tokens"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"instructions": "<string>",
"reasoning": {},
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
],
"tool_choice": "auto",
"max_output_tokens": 123,
"temperature": 123,
"top_p": 123,
"metadata": {},
"parallel_tool_calls": true,
"service_tier": "<string>",
"store": true,
"background": true,
"previous_response_id": "<string>",
"conversation": {}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}Responses API
创建一次模型响应。传入文本或图片,生成文本或 JSON 输出;也可以让模型调用你定义的函数工具。
curl --request POST \
--url https://api.moonshot.cn/v1/responses \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "kimi-k3",
"input": "<string>",
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
]
}
'import requests
url = "https://api.moonshot.cn/v1/responses"
payload = {
"model": "kimi-k3",
"input": "<string>",
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": True
}
]
}
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',
input: '<string>',
text: {},
tools: [
{
type: 'function',
name: '<string>',
description: '<string>',
parameters: {},
strict: true
}
]
})
};
fetch('https://api.moonshot.cn/v1/responses', 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/v1/responses",
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',
'input' => '<string>',
'text' => [
],
'tools' => [
[
'type' => 'function',
'name' => '<string>',
'description' => '<string>',
'parameters' => [
],
'strict' => true
]
]
]),
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/v1/responses"
payload := strings.NewReader("{\n \"model\": \"kimi-k3\",\n \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\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/v1/responses")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"kimi-k3\",\n \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/responses")
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 \"input\": \"<string>\",\n \"text\": {},\n \"tools\": [\n {\n \"type\": \"function\",\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"parameters\": {},\n \"strict\": true\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "resp_68f0c1c2d3e4f5a6b7c8d9e0",
"object": "response",
"created_at": 123,
"completed_at": 123,
"status": "in_progress",
"model": "<string>",
"output": [
{
"type": "reasoning",
"id": "rs_68f0c1c2d3e4f5a6b7c8d9e0",
"summary": [
{
"type": "summary_text",
"text": "<string>"
}
],
"encrypted_content": "<string>",
"status": "in_progress"
}
],
"usage": {
"input_tokens": 123,
"input_tokens_details": {
"cached_tokens": 123,
"cache_write_tokens": 123
},
"output_tokens": 123,
"output_tokens_details": {
"reasoning_tokens": 123
},
"total_tokens": 123
},
"incomplete_details": {
"reason": "max_output_tokens"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"instructions": "<string>",
"reasoning": {},
"text": {},
"tools": [
{
"type": "function",
"name": "<string>",
"description": "<string>",
"parameters": {},
"strict": true
}
],
"tool_choice": "auto",
"max_output_tokens": 123,
"temperature": 123,
"top_p": 123,
"metadata": {},
"parallel_tool_calls": true,
"service_tier": "<string>",
"store": true,
"background": true,
"previous_response_id": "<string>",
"conversation": {}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}调用示例
调用示例
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MOONSHOT_API_KEY"],
base_url="https://api.moonshot.cn/v1",
)
response = client.responses.create(
model="kimi-k3",
instructions="你是 Kimi,一个由 Moonshot AI 提供的人工智能助手。",
input="用一句话解释什么是上下文缓存。",
)
print(response.output_text)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: "https://api.moonshot.cn/v1",
});
const response = await client.responses.create({
model: "kimi-k3",
instructions: "你是 Kimi,一个由 Moonshot AI 提供的人工智能助手。",
input: "用一句话解释什么是上下文缓存。",
});
console.log(response.output_text);
curl https://api.moonshot.cn/v1/responses \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $MOONSHOT_API_KEY" \
--data '{
"model": "kimi-k3",
"instructions": "你是 Kimi,一个由 Moonshot AI 提供的人工智能助手。",
"input": "用一句话解释什么是上下文缓存。"
}'
授权
请求体
使用的模型 ID。本接口当前支持 kimi-k3。
"kimi-k3"
本次请求的输入。传字符串等价于一条 user 消息;传数组时按顺序给出带类型的 item,可包含历史对话、工具调用与工具结果。
顶层系统指令,作为最靠前的指令生效。
为 true 时以 SSE 事件流返回响应。
本次响应最多生成的 Token 数量。kimi-k3 默认为 131072,最大可设置为 1048576。此值为期望返回的 Token 长度,而非输入加输出的总长度。达到上限时 status 为 incomplete,incomplete_details.reason 为 max_output_tokens。
推理相关配置。
Show child attributes
Show child attributes
输出文本配置。
Show child attributes
Show child attributes
模型可调用的工具列表。
工具定义,按 type 区分。
- 函数工具
- 命名空间工具
Show child attributes
Show child attributes
控制工具调用行为。取 auto 时由模型自行决定是否调用工具。
auto 上下文缓存标识,同一会话使用相同取值可提升缓存命中率。
用于检测可能违反使用政策的用户的稳定标识符。应为唯一标识每个用户的字符串。建议对用户名或邮箱进行哈希处理以避免发送可识别信息
响应
响应创建成功
一次模型响应。
响应的唯一标识符。
"resp_68f0c1c2d3e4f5a6b7c8d9e0"
response 响应创建时的 Unix 时间戳。
响应结束时的 Unix 时间戳。status 为 completed 或 incomplete 时给出,为 in_progress 或 failed 时是 null。
响应状态。流式的起手快照为 in_progress。
in_progress, completed, incomplete, failed 产生本次响应的模型。
输出 item 数组,顺序为 reasoning、message、工具调用。
output 数组的元素,按 type 区分。
- 推理
- 消息
- 函数调用
Show child attributes
Show child attributes
本次响应的 Token 用量。
Show child attributes
Show child attributes
status 为 incomplete 时给出原因。
Show child attributes
Show child attributes
status 为 failed 时给出错误信息。
Show child attributes
Show child attributes
工具定义,按 type 区分。
- 函数工具
- 命名空间工具
Show child attributes
Show child attributes
控制工具调用行为。取 auto 时由模型自行决定是否调用工具。
auto 固定为 false。
固定为 false。
固定为 null。
固定为 null。
此页面对您有帮助吗?