gpt-6-sol
最后更新:2026-11-14
POSThttps://www.sagelib.com/chat/completions
gpt-6-sol 模型的聊天生成接口,OpenAI兼容,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
默认值:application/json 可选值:application/json 内容类型,固定为 application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
默认值:gpt-6-sol 可选值:gpt-6-sol 目标模型标识 |
*messages array |
可选值:assistant、low、high 对话消息数组,承载文本与图像输入 |
stream boolean |
默认值:false 可选值:true、false 是否以 SSE 流式增量返回响应 |
stream_options object |
可选值:include_usage、include_obfuscation 流式附加选项,仅在 stream=true 时生效 |
max_completion_tokens integer |
可选值:1 - 128000 最大输出 token 数(推理 token 与正文共享该上限) |
reasoning_effort string |
默认值:medium 可选值:none、low、medium、high、xhigh、max 推理深度档位,控制推理 token 消耗与耗时 |
response_format object |
可选值:json_object、json_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-sol",
"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
# 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/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "gpt-6-sol",
"messages": [
{
"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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-sol",
"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 {
// 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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-sol",
"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)
// 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/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-sol",
"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/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "gpt-6-sol",
"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/chat/completions";
String jsonRequestBody = """
{
"model": "gpt-6-sol",
"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/chat/completions"
jsonRequestBody := `
{
"model": "gpt-6-sol",
"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/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-sol"
}'
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/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-sol"
}
# 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/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-sol"
}
""";
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/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-sol"
}
`
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-${completion_id} |
object string |
固定 chat.completion |
created integer |
Unix 时间戳 |
model string |
实际服务模型,回带 gpt-6-sol |
choices array |
|
service_tier string |
服务层级,回带 default |
usage object |
|
prompt_tokens integer |
输入 token 数(含缓存命中量) |
completion_tokens integer |
输出 token 数(含推理 token) |
total_tokens integer |
总量 = prompt_tokens + completion_tokens |
completion_tokens_details object |
|
reasoning_tokens integer |
推理 token 数(completion_tokens 的子集) |
prompt_tokens_details object |
|
cached_tokens integer |
缓存读取量(prompt_tokens 的子集) |
cache_write_tokens integer |
缓存写入量(未命中缓存时为 0,缓存首次写入时为非 0 值) |
POSThttps://www.sagelib.com/openai/chat/completions
gpt-6-sol 模型的聊天生成接口,OpenAI直连,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
默认值:application/json 可选值:application/json 内容类型,固定为 application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
默认值:gpt-6-sol 可选值:gpt-6-sol / gpt-6-luna 目标模型标识,取值为本模型名 |
*input array |
Responses 端输入,可为字符串或内容块数组 |
instructions string |
系统指令,等价于 Chat Completions 端的 system 消息 |
stream boolean |
默认值:false 可选值:true、false 是否以流式(SSE)返回响应 |
stream_options object |
可选值:include_usage、include_obfuscation 流式附加选项,仅在 stream=true 时生效 |
max_output_tokens integer |
最大输出 token 数(Responses 端;含推理 token) |
reasoning object |
可选值:low、medium、high、xhigh、current_turn、concise、detailed Responses 端推理配置(深度档位 / 执行模式 / 跨轮推理项渲染 / 摘要粒度) |
text object |
可选值:json_object、json_schema Responses 端文本输出配置(结构化输出格式) |
temperature float |
采样温度,值越大输出越随机 |
tools array |
实际生效的工具定义数组;未传时为空数组,传入后会被规范化补全 |
tool_choice object |
默认值:auto 可选值:none、auto 工具选择策略,依赖 tools 参数同时提供 |
parallel_tool_calls boolean |
默认值:true 可选值:true、false 是否允许模型并行发起多个工具调用 |
prompt_cache_key string |
提示缓存键,用于提升相似请求的缓存命中率 |
prompt_cache_options object |
可选值:mode: implicit / explicit, ttl 提示缓存断点配置 |
service_tier string |
默认值:auto 可选值:auto、default、flex、priority、fast 服务层级(flex 半价档 / priority-Fast 双倍计费档) |
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 array(object) |
上下文压缩管理,目前仅支持 type=compaction 一种条目 |
background boolean |
默认值:false 可选值:true、false 是否以后台异步方式执行,长任务可先返回再轮询结果 |
conversation string |
会话对象 id 或会话参数,用于在服务端持久化多轮上下文 |
prompt object |
复用服务端已存储的提示模板(含变量与版本引用) |
*messages array |
可选值:low、high 对话消息数组,输入模态为 text + image,输出仅 text |
max_completion_tokens integer |
可选值:1 ~ 128000 最大输出 token 数(Chat Completions 端点),含推理 token |
reasoning_effort string |
默认值:medium 可选值:none、low、medium、high、xhigh、max 推理深度档位,档位越高推理越深、延迟与 token 消耗越大 |
response_format object |
默认值:text 可选值:json_object、json_schema 结构化输出格式,约束模型按指定结构产出 |
请求示例
curl -v 'https://www.sagelib.com/openai/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-sol",
"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-sol",
"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-sol",
"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-sol",
"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-sol",
"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-sol",
"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-sol",
"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-sol",
"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": "auto",
"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-sol"
}'
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": "auto",
"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-sol"
}
# 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": "auto",
"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-sol"
}
""";
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": "auto",
"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-sol"
}
`
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": "What model are you? Which company made you? When is your knowledge cutoff? Briefly describe your capability boundaries.",
"role": "user"
}
],
"model": "gpt-6-sol"
}'
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-sol"
}
# 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-sol"
}
""";
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-sol"
}
`
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": "List the time complexity of 5 sorting algorithms; output as a JSON array with each item containing name, best, average, worst fields; ensure valid JSON output.",
"role": "user"
}
],
"model": "gpt-6-sol",
"response_format": {
"type": "json_object"
}
}'
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": "List the time complexity of 5 sorting algorithms; output as a JSON array with each item containing name, best, average, worst fields; ensure valid JSON output.",
"role": "user"
}
],
"model": "gpt-6-sol",
"response_format": {
"type": "json_object"
}
}
# 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": "List the time complexity of 5 sorting algorithms; output as a JSON array with each item containing name, best, average, worst fields; ensure valid JSON output.",
"role": "user"
}
],
"model": "gpt-6-sol",
"response_format": {
"type": "json_object"
}
}
""";
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": "List the time complexity of 5 sorting algorithms; output as a JSON array with each item containing name, best, average, worst fields; ensure valid JSON output.",
"role": "user"
}
],
"model": "gpt-6-sol",
"response_format": {
"type": "json_object"
}
}
`
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": "low",
"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-sol"
}'
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": "low",
"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-sol"
}
# 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": "low",
"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-sol"
}
""";
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": "low",
"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-sol"
}
`
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 |
响应 ID(resp_ 前缀) |
object string |
固定为 response |
model string |
模型名 |
status string |
响应状态,成功为 completed |
created_at / completed_at integer |
创建 / 完成时间戳(秒) |
output array |
输出项数组:reasoning(加密推理,encrypted_content,content 为空数组)、message(文本,phase="final_answer",文本在 content[0].text,type="output_text") |
reasoning object |
回带生效的 context / effort / mode / summary |
text object |
回带 format.type 与 verbosity |
usage object |
input_tokens / input_tokens_details(cache_write_tokens、cached_tokens)/ output_tokens / output_tokens_details.reasoning_tokens / total_tokens |
temperature / top_p number |
服务端生效的采样参数 |
service_tier string |
实际生效服务层级 |
store / truncation / prompt_cache_retention - |
响应回带值 |
tool_usage object |
内置工具用量(image_gen token 明细、web_search.num_requests) |
tools array |
请求中工具定义的回带(归一化后) |
content_filters array |
内容过滤结果(prompt / completion 两段) |
error object |
成功时为 null |