kimi-k3

最后更新:2026-11-14

POSThttps://www.sagelib.com/responses

kimi-k3 模型的响应生成接口,OpenAI兼容,支持多轮上下文、流式输出、工具调用、结构化输出等。

接口鉴权方式请参考:API接入与鉴权

请求参数

请求头

参数名称 描述
*Authorization string 鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN}
*Content-Type string 默认值:application/json
可选值:application/json
内容类型,固定为 application/json

Body 参数

参数名称 描述
*model string 可选值:"kimi-k3"
指定调用的模型名称
*input string 可选值:String or array of message items
输入内容:字符串或消息项数组(role/type/content;数组形态 content 内用 input_text 块)
instructions string 可选值:String
系统级指令(独立顶层字段)
max_output_tokens integer 默认值:131072
可选值:16 ~ 1048576
限制生成的最大 token 数(含推理)
reasoning object 可选值:high、max
推理配置对象(effort 档位)
text object 可选值:format.type: json_schema etc.
输出格式配置(JSON Schema 结构化输出)
stream boolean 默认值:false
可选值:true、false
是否启用流式(SSE)响应
tools array 可选值:Array of tool definitions, flat Responses format
工具定义列表(name/description/parameters,无 function 包装)
tool_choice string 默认值:auto
可选值:none、auto、required
控制工具调用策略
prompt_cache_key string 可选值:String
前缀缓存键
safety_identifier string 可选值:String
安全标识符

请求示例

curl -v 'https://www.sagelib.com/responses' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [
      {
        "role": "user",
        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
      }
    ]
  }'
import json
import requests

base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/responses"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
    "model": "kimi-k3",
    "messages": [
        {
            "role": "user",
            "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/responses";
        String jsonRequestBody = """
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ]
            }
            """;
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).header("Authorization", "Bearer " + apiKey).header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody)).build();
        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/responses"
    jsonRequestBody := `
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ]
            }
`
    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/responses' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [
      {
        "role": "user",
        "content": "How is the weather in Beijing today? Please use a tool to query."
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Query weather for a specified city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "City name"
              }
            },
            "required": [
              "city"
            ]
          }
        }
      }
    ]
  }'
import json
import requests

base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/responses"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
    "model": "kimi-k3",
    "messages": [
        {
            "role": "user",
            "content": "How is the weather in Beijing today? Please use a tool to query."
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Query weather for a specified city",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {
                            "type": "string",
                            "description": "City name"
                        }
                    },
                    "required": [
                        "city"
                    ]
                }
            }
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/responses";
        String jsonRequestBody = """
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "description": "Query weather for a specified city",
                            "parameters": {
                                "type": "object",
                                "properties": {
                                    "city": {
                                        "type": "string",
                                        "description": "City name"
                                    }
                                },
                                "required": [
                                    "city"
                                ]
                            }
                        }
                    }
                ]
            }
            """;
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).header("Authorization", "Bearer " + apiKey).header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody)).build();
        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/responses"
    jsonRequestBody := `
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "description": "Query weather for a specified city",
                            "parameters": {
                                "type": "object",
                                "properties": {
                                    "city": {
                                        "type": "string",
                                        "description": "City name"
                                    }
                                },
                                "required": [
                                    "city"
                                ]
                            }
                        }
                    }
                ]
            }
`
    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}

响应参数

Body 参数

参数名称 描述
id string 响应 ID,如 resp_${response_id}
object string 固定为 response
status string completed(完成)/ in_progress(进行中)
model string 实际使用的模型名称
output array 输出项数组:推理时为 [reasoning, message] 两项
output[] (type=reasoning) object 推理项:content=null、summary[] 含推理摘要文本
output[] (type=message) object 消息项:content[] 含 output_text 块(可读文本)
usage object
    input_tokens integer 输入 token 数
    output_tokens integer 输出 token 数
    output_tokens_details object
        reasoning_tokens integer 推理消耗 token 数
POSThttps://www.sagelib.com/openai/responses

kimi-k3 模型的响应生成接口,OpenAI 直连模式,支持多轮上下文、流式输出、工具调用、结构化输出等。

接口鉴权方式请参考:API接入与鉴权

请求参数

请求头

参数名称 描述
*Authorization string 鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN}
*Content-Type string 默认值:application/json
可选值:application/json
内容类型,固定为 application/json

Body 参数

参数名称 描述
*model string 可选值:"kimi-k3"
指定调用的模型名称
*input string 可选值:String or array of message items
输入内容:字符串或消息项数组(role/type/content;数组形态 content 内用 input_text 块)
instructions string 可选值:String
系统级指令(独立顶层字段)
max_output_tokens integer 默认值:131072
可选值:16 ~ 1048576
限制生成的最大 token 数(含推理)
reasoning object 可选值:high、max
推理配置对象(effort 档位)
text object 可选值:format.type: json_schema etc.
输出格式配置(JSON Schema 结构化输出)
stream boolean 默认值:false
可选值:true、false
是否启用流式(SSE)响应
tools array 可选值:Array of tool definitions, flat Responses format
工具定义列表(name/description/parameters,无 function 包装)
tool_choice string 默认值:auto
可选值:none、auto、required
控制工具调用策略
prompt_cache_key string 可选值:String
前缀缓存键
safety_identifier string 可选值:String
安全标识符

请求示例

curl -v 'https://www.sagelib.com/openai/responses' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [
      {
        "role": "user",
        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
      }
    ]
  }'
import json
import requests

base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/openai/responses"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
    "model": "kimi-k3",
    "messages": [
        {
            "role": "user",
            "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/openai/responses";
        String jsonRequestBody = """
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ]
            }
            """;
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).header("Authorization", "Bearer " + apiKey).header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody)).build();
        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/openai/responses"
    jsonRequestBody := `
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ]
            }
`
    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/openai/responses' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "messages": [
      {
        "role": "user",
        "content": "How is the weather in Beijing today? Please use a tool to query."
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Query weather for a specified city",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "City name"
              }
            },
            "required": [
              "city"
            ]
          }
        }
      }
    ]
  }'
import json
import requests

base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/openai/responses"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
    "model": "kimi-k3",
    "messages": [
        {
            "role": "user",
            "content": "How is the weather in Beijing today? Please use a tool to query."
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Query weather for a specified city",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "city": {
                            "type": "string",
                            "description": "City name"
                        }
                    },
                    "required": [
                        "city"
                    ]
                }
            }
        }
    ]
}
response = requests.post(url, headers=headers, json=data)
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/openai/responses";
        String jsonRequestBody = """
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "description": "Query weather for a specified city",
                            "parameters": {
                                "type": "object",
                                "properties": {
                                    "city": {
                                        "type": "string",
                                        "description": "City name"
                                    }
                                },
                                "required": [
                                    "city"
                                ]
                            }
                        }
                    }
                ]
            }
            """;
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).header("Authorization", "Bearer " + apiKey).header("Content-Type", "application/json").POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody)).build();
        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/openai/responses"
    jsonRequestBody := `
            {
                "model": "kimi-k3",
                "messages": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "description": "Query weather for a specified city",
                            "parameters": {
                                "type": "object",
                                "properties": {
                                    "city": {
                                        "type": "string",
                                        "description": "City name"
                                    }
                                },
                                "required": [
                                    "city"
                                ]
                            }
                        }
                    }
                ]
            }
`
    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}

响应参数

Body 参数

参数名称 描述
id string 响应 ID,如 resp_${response_id}
object string 固定为 response
status string completed(完成)/ in_progress(进行中)
model string 实际使用的模型名称
output array 输出项数组:推理时为 [reasoning, message] 两项
output[] (type=reasoning) object 推理项:content=null、summary[] 含推理摘要文本
output[] (type=message) object 消息项:content[] 含 output_text 块(可读文本)
usage object
    input_tokens integer 输入 token 数
    output_tokens integer 输出 token 数
    output_tokens_details object
        reasoning_tokens integer 推理消耗 token 数