gpt-6-luna
最后更新:2026-11-14
POSThttps://www.sagelib.com/chat/completions
gpt-6-luna 模型的聊天生成接口,OpenAI兼容,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
默认值:application/json 可选值:application/json 内容类型,固定为 application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
默认值:gpt-6-luna 可选值:gpt-6-sol、gpt-6-luna 目标模型标识 |
*messages array |
可选值:user、low、high 对话消息数组,输入模态为文本 + 图像 |
stream boolean |
默认值:false 可选值:true、false 是否以流式(SSE)返回响应 |
stream_options object |
可选值:include_usage、include_obfuscation 流式附加选项,仅 stream=true 时生效 |
max_completion_tokens integer |
可选值:1 - 128000 最大输出 token 数 |
reasoning_effort string |
默认值:medium 可选值:none、low、medium、high、xhigh、max 推理深度档位 |
response_format object |
默认值:text 可选值:json_object、json_schema 结构化输出格式;type=json_schema 时需在 json_schema 子字段提供 Schema 定义 |
temperature float |
可选值:Default value 1 only 采样温度,值越大输出越随机 |
prompt_cache_options object |
可选值:mode: implicit / explicit; ttl: 30m 提示缓存断点配置 |
请求示例
curl -v 'https://www.sagelib.com/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"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/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"model": "gpt-6-luna",
"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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-luna",
"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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-luna",
"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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}'
import json
import requests
base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": False
}
}
},
"required": [
"algorithms"
],
"additionalProperties": False
},
"strict": False
}
},
"max_completion_tokens": 2000
}
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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}
""";
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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}
`
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}'
import json
import requests
base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
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/chat/completions";
String jsonRequestBody = """
{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
""";
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/chat/completions"
jsonRequestBody := `
{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
`
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 |
本次响应唯一标识,以 chatcmpl- 开头 |
object string |
固定为 chat.completion |
created integer |
Unix 时间戳 |
model string |
实际生效的模型名 |
choices array |
生成结果数组,通常长度为 1 |
service_tier string |
实际生效的服务层级 |
usage object |
|
prompt_tokens integer |
输入 token 数 |
completion_tokens integer |
输出 token 数 |
total_tokens integer |
总 token 数 |
completion_tokens_details object |
|
reasoning_tokens integer |
其中推理 token 数 |
prompt_tokens_details object |
|
cached_tokens integer |
命中缓存的输入 token 数 |
cache_write_tokens integer |
写入缓存的 token 数 |
POSThttps://www.sagelib.com/openai/chat/completions
gpt-6-luna 模型的聊天生成接口,OpenAI直连,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
默认值:application/json 可选值:application/json 内容类型,固定为 application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
默认值:gpt-6-luna 可选值:gpt-6-sol、gpt-6-luna 目标模型标识名,本文档固定为 gpt-6-luna |
*messages array |
可选值:user、low、high 对话消息数组,输入模态为文本 + 图像 |
stream boolean |
默认值:false 可选值:true、false 是否以流式(SSE)返回响应 |
stream_options object |
可选值:include_usage、include_obfuscation 流式附加选项,仅 stream=true 时生效 |
max_completion_tokens integer |
可选值:1 - 128000 最大输出 token 数 |
reasoning_effort string |
默认值:medium 可选值:none、low、medium、high、xhigh、max 推理深度档位 |
response_format object |
默认值:text 可选值:json_object、json_schema 结构化输出格式 |
temperature float |
采样温度,值越大输出越随机 |
tools array |
工具定义数组,模型可据此发起工具调用;使用函数工具时须同时设置 reasoning_effort=none |
tool_choice object |
默认值:auto 可选值:none、auto 工具选择策略,须与 tools 同时提供 |
parallel_tool_calls boolean |
默认值:true 可选值:true、false 是否允许模型并行发起多个工具调用;须与 tools 同时提供 |
prompt_cache_options object |
可选值:mode: implicit / explicit; ttl: 30m 提示缓存断点配置 |
*input array |
对话输入,可为字符串或内容块数组,图像经 input_image 块传入 |
instructions string |
系统指令,等价于 Chat Completions 端的 system 消息 |
max_output_tokens integer |
最大输出 token 数 |
reasoning object |
默认值:context: all_turns 可选值:low、medium、high、xhigh、current_turn、concise、detailed 推理配置对象,effort 控制推理深度档位,mode 控制推理模式,context 控制推理上下文范围,summary 控制推理摘要详细程度 |
text object |
默认值:format.type: text 可选值:json_object、json_schema 文本输出配置,json_schema 档须在 format 内提供 JSON Schema |
prompt_cache_key string |
提示缓存键,用于提升相似请求的缓存命中率 |
service_tier string |
默认值:auto 可选值:auto、default、flex、priority、fast 服务层级;fast 与 priority 等价 |
store boolean |
默认值:false 可选值:true、false 是否存储本次响应,供后续 previous_response_id 续接 |
metadata object |
附加元数据键值对,用于业务侧标记与检索 |
safety_identifier string |
安全标识符,用于滥用追踪 |
previous_response_id string |
上一轮响应 id,用于多轮续接并保留推理状态 |
truncation string |
默认值:disabled 可选值:auto、disabled 上下文超限时的截断策略;disabled 为默认,超限直接报错,auto 由服务端自动截断 |
include array |
可选值:file_search_call.results、web_search_call.results、web_search_call.action.sources、message.input_image.image_url、computer_call_output.output.image_url、code_interpreter_call.outputs、reasoning.encrypted_content、message.output_text.logprobs 指定响应中额外回带的字段清单 |
max_tool_calls integer |
单次请求允许的最大工具调用次数 |
context_management object |
上下文压缩管理,可配置 compact_threshold 指定触发压缩的 token 阈值 |
background boolean |
默认值:false 可选值:true、false 是否以后台异步方式执行,长任务可先返回再轮询结果 |
conversation string |
会话对象 id 或会话参数,用于在服务端持久化多轮上下文 |
prompt object |
复用服务端已存储的提示模板(含变量与版本引用),须传入服务端已存在的模板 id |
请求示例
curl -v 'https://www.sagelib.com/openai/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"content": "What model are you? Which company made you? When is your knowledge cutoff? Briefly describe your capability boundaries.",
"role": "user"
}
],
"model": "gpt-6-luna"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"messages": [
{
"content": "What model are you? Which company made you? When is your knowledge cutoff? Briefly describe your capability boundaries.",
"role": "user"
}
],
"model": "gpt-6-luna"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"messages": [
{
"content": "What model are you? Which company made you? When is your knowledge cutoff? Briefly describe your capability boundaries.",
"role": "user"
}
],
"model": "gpt-6-luna"
}
""";
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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"messages": [
{
"content": "What model are you? Which company made you? When is your knowledge cutoff? Briefly describe your capability boundaries.",
"role": "user"
}
],
"model": "gpt-6-luna"
}
`
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)
// Pretty-print the returned JSON data
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": False
}
}
},
"required": [
"algorithms"
],
"additionalProperties": False
},
"strict": False
}
},
"max_completion_tokens": 2000
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}
""";
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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "List the time complexity of 5 common sorting algorithms; output as a JSON object with an algorithms array, each item containing name/best/average/worst fields."
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "algo_list",
"schema": {
"type": "object",
"properties": {
"algorithms": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"best": {
"type": "string"
},
"average": {
"type": "string"
},
"worst": {
"type": "string"
}
},
"required": [
"name",
"best",
"average",
"worst"
],
"additionalProperties": false
}
}
},
"required": [
"algorithms"
],
"additionalProperties": false
},
"strict": false
}
},
"max_completion_tokens": 2000
}
`
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)
// Pretty-print the returned JSON data
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
""";
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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"messages": [
{
"content": [
{
"image_url": {
"detail": "high",
"url": "${image_url}"
},
"type": "image_url"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
`
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)
// Pretty-print the returned JSON data
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
]
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-luna",
"input": [
{
"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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-luna",
"input": [
{
"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)
// Pretty-print the returned JSON data
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Get weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Get weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
]
}
}
]
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Get weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-luna",
"input": [
{
"role": "user",
"content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "Get weather",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"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)
// Pretty-print the returned JSON data
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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"input": [
{
"content": [
{
"detail": "low",
"image_url": "${image_url}",
"type": "input_image"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "input_text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"input": [
{
"content": [
{
"detail": "low",
"image_url": "${image_url}",
"type": "input_image"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "input_text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned 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/chat/completions";
String jsonRequestBody = """
{
"input": [
{
"content": [
{
"detail": "low",
"image_url": "${image_url}",
"type": "input_image"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "input_text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
""";
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 {
// Use ofInputStream to handle the streaming response
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;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
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/chat/completions"
jsonRequestBody := `
{
"input": [
{
"content": [
{
"detail": "low",
"image_url": "${image_url}",
"type": "input_image"
},
{
"text": "Carefully observe this image and describe the subject, scene, and style details.",
"type": "input_text"
}
],
"role": "user"
}
],
"model": "gpt-6-luna"
}
`
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)
// Pretty-print the returned JSON data
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 |
本次响应唯一标识(如 chatcmpl-...) |
object string |
固定为 chat.completion |
created integer |
Unix 时间戳 |
model string |
实际生效的模型名 |
choices array |
生成结果数组,通常长度为 1 |
prompt_filter_results array |
提示词过滤结果(直连网关特有) |
routing object |
后端路由信息(直连网关特有) |
service_tier string |
实际生效的服务层级 |
system_fingerprint string |
系统指纹,本网关返回 null |
usage object |
|
prompt_tokens integer |
输入 token 数 |
completion_tokens integer |
输出 token 数 |
total_tokens integer |
总 token 数 |
completion_tokens_details object |
|
reasoning_tokens integer |
推理 token 数(本协议唯一的推理度量字段) |
prompt_tokens_details object |
|
cached_tokens integer |
命中缓存的输入 token 数 |
cache_write_tokens integer |
写入缓存的 token 数 |
latency_checkpoint object |
各阶段延迟检查点(直连网关特有) |