gpt-6-astra

最后更新:2026-11-14

POSThttps://www.sagelib.com/chat/completions

gpt-6-astra 模型的聊天生成接口,OpenAI 兼容协议,支持多轮上下文、流式输出、工具调用、结构化输出等。

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

请求参数

请求头

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

Body 参数

参数名称 描述
*model string 可选值:gpt-6-astra
模型标识名,固定为 gpt-6-astra
*messages array 可选值:Array of message objects
对话消息列表,支持 system/developer/user/assistant/tool 角色,图像经 image_url 内容块传入(detail: auto/low/high)
max_completion_tokens integer 可选值:≤128K
输出 token 上限(含推理 token)
reasoning_effort string 默认值:medium
可选值:low、medium、high、xhigh
推理深度档位
response_format object 可选值:json_object、json_schema
结构化输出格式
stream boolean 默认值:false
可选值:true、false
是否以 SSE 流式返回
stream_options object 可选值:include_usage
流式选项,stream=true 时生效
n integer 默认值:1
可选值:Up to 128
生成候选数
prompt_cache_options object 可选值:ttl minimum 30m
提示缓存选项
metadata object 可选值:Up to 16 pairs, key/value ≤512 characters
附加键值对

请求示例

curl -v 'https://www.sagelib.com/chat/completions' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-astra",
    "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-astra",
    "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-astra",
                "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-astra",
                "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-astra",
    "messages": [
      {
        "role": "user",
        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
      }
    ],
    "response_format": {
      "type": "text"
    }
  }'
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-astra",
    "messages": [
        {
            "role": "user",
            "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
        }
    ],
    "response_format": {
        "type": "text"
    }
}

# 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-astra",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ],
                "response_format": {
                    "type": "text"
                }
            }
            """;

        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-astra",
                "messages": [
                    {
                        "role": "user",
                        "content": "What model are you? Which company made you? When were you launched? Briefly describe your capability boundaries."
                    }
                ],
                "response_format": {
                    "type": "text"
                }
            }
`

    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": "[Enterprise Knowledge Base v3.2] ${company_name} is a technology company focusing on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform. 1. Refund policy: unused member subscriptions can be fully refunded within 7 days; API quota is refunded proportionally within 90 days; ... (knowledge base long text truncated; the original use case is an enterprise knowledge base of about 3600 characters repeated 3 times to trigger prompt caching)",
        "role": "user"
      }
    ],
    "model": "gpt-6-astra",
    "prompt_cache_options": {
      "ttl": "30m"
    }
  }'
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": "[Enterprise Knowledge Base v3.2] ${company_name} is a technology company focusing on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform. 1. Refund policy: unused member subscriptions can be fully refunded within 7 days; API quota is refunded proportionally within 90 days; ... (knowledge base long text truncated; the original use case is an enterprise knowledge base of about 3600 characters repeated 3 times to trigger prompt caching)",
            "role": "user"
        }
    ],
    "model": "gpt-6-astra",
    "prompt_cache_options": {
        "ttl": "30m"
    }
}

# 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": "[Enterprise Knowledge Base v3.2] ${company_name} is a technology company focusing on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform. 1. Refund policy: unused member subscriptions can be fully refunded within 7 days; API quota is refunded proportionally within 90 days; ... (knowledge base long text truncated; the original use case is an enterprise knowledge base of about 3600 characters repeated 3 times to trigger prompt caching)",
                        "role": "user"
                    }
                ],
                "model": "gpt-6-astra",
                "prompt_cache_options": {
                    "ttl": "30m"
                }
            }
            """;

        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": "[Enterprise Knowledge Base v3.2] ${company_name} is a technology company focusing on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform. 1. Refund policy: unused member subscriptions can be fully refunded within 7 days; API quota is refunded proportionally within 90 days; ... (knowledge base long text truncated; the original use case is an enterprise knowledge base of about 3600 characters repeated 3 times to trigger prompt caching)",
                        "role": "user"
                    }
                ],
                "model": "gpt-6-astra",
                "prompt_cache_options": {
                    "ttl": "30m"
                }
            }
`

    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- 开头的响应 ID
object string 固定为 chat.completion
model string 模型名
created integer 创建时间戳(Unix 秒)
choices array 候选数组,每项含 message / finish_reason / index
service_tier string 服务层级回带值
usage object prompt_tokens / completion_tokens / total_tokens 及 reasoning_tokens 明细

流式响应(SSE),content-type 为 text/event-stream。data 为存储消息的集合,最后一个 data 值固定为 [DONE] 表示响应结束。

响应示例

{
  "id": "chatcmpl-${completion_id}",
  "model": "gpt-6-astra",
  "object": "chat.completion",
  "created": 1788758930,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "- **What model**: I am ChatGPT, based on OpenAI's large language model, provided via API. ... (body truncated)"
      },
      "finish_reason": "stop",
      "logprobs": null
    }
  ],
  "service_tier": "default",
  "usage": {
    "prompt_tokens": 29,
    "completion_tokens": 254,
    "total_tokens": 283,
    "completion_tokens_details": {
      "reasoning_tokens": 101
    }
  }
}
POSThttps://www.sagelib.com/openai/chat/completions

gpt-6-astra 模型的聊天生成接口,OpenAI 兼容协议,支持多轮上下文、流式输出、工具调用、结构化输出等。

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

请求参数

请求头

参数名称 描述
*Content-Type string application/json(JSON 端点)或 multipart/form-data; boundary=...(multipart 端点,保持原始 boundary)
*Authorization string 鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN}

Body 参数

参数名称 描述
*model string 可选值:gpt-6-astra
模型标识名,固定为 gpt-6-astra
*messages array 可选值:Array of message objects
对话消息列表,支持 system/developer/user/assistant/tool 角色,图像经 image_url 内容块传入(detail: auto/low/high)
max_completion_tokens integer 可选值:≤128K
输出 token 上限(含推理 token)
reasoning_effort string 默认值:medium
可选值:low、medium、high、xhigh
推理深度档位
response_format object 可选值:json_object、json_schema
结构化输出格式
stream boolean 默认值:false
可选值:true、false
是否以 SSE 流式返回
stream_options object 可选值:include_usage
流式选项,stream=true 时生效
verbosity string 默认值:medium
可选值:low、medium、high
输出详细程度
n integer 默认值:1
可选值:Up to 128
生成候选数
service_tier string 默认值:auto
可选值:auto、default、flex、priority、fast
服务层级选择
prompt_cache_key string 缓存命中优化的稳定 key
prompt_cache_options object 可选值:ttl minimum 30m
提示缓存选项
store boolean 默认值:false
可选值:true、false
是否存储响应供检索
metadata object 可选值:Up to 16 pairs, key/value ≤512 characters
附加键值对
safety_identifier string 可选值:≤64 characters
稳定用户标识,用于滥用检测
*input string 对话输入,支持字符串或消息对象数组(含 role/content),图像经 input_image 块传入(detail: auto/low/high)
instructions string 系统指令,插入对话最前
max_output_tokens integer 输出 token 上限(含推理 token)
reasoning object 可选值:medium、high、xhigh、concise、current_turn、pro
推理配置对象,effort 控制推理深度档位
text object 可选值:json_object、medium、high
输出格式配置,支持结构化输出与详细程度控制
tools array 工具定义列表,支持 function 类型
tool_choice string 默认值:auto
可选值:none、auto
工具选择策略
parallel_tool_calls boolean 默认值:true
可选值:true、false
是否允许并行工具调用
max_tool_calls integer 单请求内置工具总调用上限
prompt object 提示词模板复用对象,与 input 互斥
previous_response_id string 前序响应 ID,用于多轮续接
background boolean 默认值:false
可选值:true、false
后台模式,适用于长任务防超时
conversation string 会话 ID,用于多智能体编排
include array 附加回带项
stop string 停止词列表

请求示例

curl -v 'https://www.sagelib.com/openai/chat/completions' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-astra",
    "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/chat/completions"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
    "model": "gpt-6-astra",
    "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/chat/completions";
        String jsonRequestBody = """
            {
                "model": "gpt-6-astra",
                "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/chat/completions"
    jsonRequestBody := `
            {
                "model": "gpt-6-astra",
                "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/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-astra",
    "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-astra",
    "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-astra",
                "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-astra",
                "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": "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-astra"
  }'
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-astra"
}

# 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-astra"
            }
            """;

        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-astra"
            }
`

    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-astra",
    "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-astra",
    "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-astra",
                "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-astra",
                "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-astra",
    "input": [
      {
        "role": "user",
        "content": "How is the weather in Beijing today? Please use a tool to query the weather."
      }
    ],
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Query the weather of a specified city",
        "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-astra",
    "input": [
        {
            "role": "user",
            "content": "How is the weather in Beijing today? Please use a tool to query the weather."
        }
    ],
    "tools": [
        {
            "type": "function",
            "name": "get_weather",
            "description": "Query the weather of a specified city",
            "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-astra",
                "input": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query the weather."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "name": "get_weather",
                        "description": "Query the weather of a specified city",
                        "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-astra",
                "input": [
                    {
                        "role": "user",
                        "content": "How is the weather in Beijing today? Please use a tool to query the weather."
                    }
                ],
                "tools": [
                    {
                        "type": "function",
                        "name": "get_weather",
                        "description": "Query the weather of a specified city",
                        "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": "[Enterprise Knowledge Base v3.2] Yunzhi Technology focuses on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform, supporting unified access and quality verification for multi-vendor models such as OpenAI/Anthropic/Gemini. 1. Refund policy: unused member subscriptions fully refundable within 7 days; API quota refunded proportionally within 90 days; physical goods accepted within 15 days with 7-day no-reason return. ... (knowledge base long text truncated; original case is an enterprise KB of about 3600 chars repeated 3 times to trigger prompt caching)",
        "role": "user"
      }
    ],
    "model": "gpt-6-astra",
    "prompt_cache_options": {
      "ttl": "30m"
    }
  }'
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": "[Enterprise Knowledge Base v3.2] Yunzhi Technology focuses on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform, supporting unified access and quality verification for multi-vendor models such as OpenAI/Anthropic/Gemini. 1. Refund policy: unused member subscriptions fully refundable within 7 days; API quota refunded proportionally within 90 days; physical goods accepted within 15 days with 7-day no-reason return. ... (knowledge base long text truncated; original case is an enterprise KB of about 3600 chars repeated 3 times to trigger prompt caching)",
            "role": "user"
        }
    ],
    "model": "gpt-6-astra",
    "prompt_cache_options": {
        "ttl": "30m"
    }
}

# 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": "[Enterprise Knowledge Base v3.2] Yunzhi Technology focuses on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform, supporting unified access and quality verification for multi-vendor models such as OpenAI/Anthropic/Gemini. 1. Refund policy: unused member subscriptions fully refundable within 7 days; API quota refunded proportionally within 90 days; physical goods accepted within 15 days with 7-day no-reason return. ... (knowledge base long text truncated; original case is an enterprise KB of about 3600 chars repeated 3 times to trigger prompt caching)",
                        "role": "user"
                    }
                ],
                "model": "gpt-6-astra",
                "prompt_cache_options": {
                    "ttl": "30m"
                }
            }
            """;

        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": "[Enterprise Knowledge Base v3.2] Yunzhi Technology focuses on large model gateway and testing platforms, founded in Q3 2024, headquartered in Hangzhou. The core product is AI Gateway Test Platform, supporting unified access and quality verification for multi-vendor models such as OpenAI/Anthropic/Gemini. 1. Refund policy: unused member subscriptions fully refundable within 7 days; API quota refunded proportionally within 90 days; physical goods accepted within 15 days with 7-day no-reason return. ... (knowledge base long text truncated; original case is an enterprise KB of about 3600 chars repeated 3 times to trigger prompt caching)",
                        "role": "user"
                    }
                ],
                "model": "gpt-6-astra",
                "prompt_cache_options": {
                    "ttl": "30m"
                }
            }
`

    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- 开头的响应 ID
object string 固定为 chat.completion
model string 模型名
choices array 候选数组,每项含 message / finish_reason / index
usage object prompt_tokens / completion_tokens(含推理 token 明细)