gemini-4-argon
最后更新:2026-11-14
POSThttps://www.sagelib.com/chat/completions
gemini-4-argon 模型的聊天生成接口,OpenAI兼容,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:application/json application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
可选值:gemini-4-argon 指定调用的模型名 |
*messages array |
可选值:role:system / user / assistant;content 为纯字符串或多模态内容块数组 对话消息数组,承载全部对话与多模态内容 |
tools array |
可选值:type:function;function.name / function.description / function.parameters 工具定义数组,模型可据此发起工具调用 |
tool_choice string |
可选值:none / auto / required 工具选择策略:none 不调用工具、auto 由模型自主决定、required 强制调用 |
reasoning_effort string |
默认值:medium 可选值:low / medium / high 推理强度档位,档位越高思考越充分、首 token 延迟越长 |
max_tokens integer |
默认值:65536 可选值:1 ~ 1048576 最大输出 token 数,思考与正文共享该上限 |
stream boolean |
可选值:true / false 是否以 SSE 流式返回响应 |
stream_options object |
可选值:include_usage:true / false 流式响应附加选项,控制是否在流末尾返回 usage 统计 |
response_format object |
可选值:type:text / json_object / json_schema 响应格式约束,用于强制结构化输出 |
stop array |
可选值:字符串数组 停止序列,命中任一字符串即停止生成 |
seed integer |
可选值:整数 随机种子,固定后模型尽力返回确定性结果 |
service_tier string |
默认值:default 可选值:default / priority / flex 服务层级,指定请求的算力优先级 |
user string |
可选值:字符串 终端用户标识,用于上游滥用追踪 |
请求示例
curl -v 'https://www.sagelib.com/chat/completions' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-4-argon",
"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": "gemini-4-argon",
"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": "gemini-4-argon",
"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": "gemini-4-argon",
"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": "gemini-4-argon",
"messages": [
{
"content": "How is the weather in Beijing today? Please query it with a tool.",
"role": "user"
}
],
"tool_choice": "required",
"tools": [
{
"function": {
"description": "Get the weather information of a specified city",
"name": "get_weather",
"parameters": {
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
},
"type": "function"
}
]
}'
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": "gemini-4-argon",
"messages": [{
"content": "How is the weather in Beijing today? Please query it with a tool.",
"role": "user"
}],
"tool_choice": "required",
"tools": [{
"function": {
"description": "Get the weather information of a specified city",
"name": "get_weather",
"parameters": {
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"],
"type": "object"
}
},
"type": "function"
}]
}
# 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": "gemini-4-argon",
"messages": [
{
"content": "How is the weather in Beijing today? Please query it with a tool.",
"role": "user"
}
],
"tool_choice": "required",
"tools": [
{
"function": {
"description": "Get the weather information of a specified city",
"name": "get_weather",
"parameters": {
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
},
"type": "function"
}
]
}
""";
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": "gemini-4-argon",
"messages": [
{
"content": "How is the weather in Beijing today? Please query it with a tool.",
"role": "user"
}
],
"tool_choice": "required",
"tools": [
{
"function": {
"description": "Get the weather information of a specified city",
"name": "get_weather",
"parameters": {
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
},
"type": "function"
}
]
}
}
`
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": "gemini-4-argon",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "${image_url}"
}
},
{
"type": "text",
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
]
}
]
}'
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": "gemini-4-argon",
"messages": [{
"role": "user",
"content": [{
"type": "image_url",
"image_url": {
"url": "${image_url}"
}
}, {
"type": "text",
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}]
}]
}
# 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": "gemini-4-argon",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "${image_url}"
}
},
{
"type": "text",
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
]
}
]
}
""";
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": "gemini-4-argon",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "${image_url}"
}
},
{
"type": "text",
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
]
}
]
}
}
`
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 |
响应唯一标识 |
model string |
实际服务的模型名,回带 gemini-4-argon |
object string |
可选值:chat.completion 固定 chat.completion |
created integer |
响应创建时间戳 |
choices array |
候选结果数组 |
choices[].index integer |
候选序号 |
choices[].message.role string |
可选值:assistant 固定 assistant |
choices[].message.content string |
模型输出的文本内容 |
choices[].message.reasoning_content string |
思考内容字段,非思考档位下为空串 |
choices[].message.tool_calls array |
工具调用结果,仅在触发工具调用时出现 |
choices[].finish_reason string |
可选值:stop / tool_calls / length 结束原因:stop 正常结束、tool_calls 工具调用、length 截断 |
service_tier string |
可选值:ON_DEMAND 服务层级,回带 ON_DEMAND |
usage object |
token 用量统计 |
usage.prompt_tokens integer |
输入 token 数 |
usage.completion_tokens integer |
输出 token 数 |
usage.total_tokens integer |
总 token 数 |
usage.completion_tokens_details.reasoning_tokens integer |
思考消耗的 token 数 |
usage.prompt_tokens_details.cached_tokens integer |
命中缓存的输入 token 数 |
usage.prompt_tokens_details.cache_write_tokens integer |
写入缓存的输入 token 数 |
POSThttps://www.sagelib.com/gemini/v1beta/models/{model}:streamGenerateContent
gemini-4-argon 模型的聊天生成接口,Gemini直连,支持多轮上下文、流式输出、工具调用、结构化输出等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Content-Type string |
可选值:application/json application/json |
*x-goog-api-key string |
鉴权令牌,格式为 ${AIGATEWAY_TOKEN} |
Body 参数
| 参数名称 | 描述 |
|---|---|
model string |
可选值:gemini-4-argon 指定调用的模型名 |
tools array |
可选值:functionDeclarations 及内置工具 工具定义数组,支持自定义函数与内置工具 |
*contents array |
可选值:role:user / model;parts:text / inlineData / fileData Gemini 原生对话内容数组,parts 内可含文本、内联 base64 与文件引用 |
system_instruction object |
可选值:parts 数组 系统指令,用于设定模型行为与角色 |
safety_settings array |
可选值:category:HARM_CATEGORY_HATE_SPEECH / HARM_CATEGORY_DANGEROUS_CONTENT / HARM_CATEGORY_HARASSMENT / HARM_CATEGORY_SEXUALLY_EXPLICIT;threshold:OFF / BLOCK_NONE / BLOCK_ONLY_HIGH / BLOCK_MEDIUM_AND_ABOVE / BLOCK_LOW_AND_ABOVE 安全过滤设置,每项含危害类别与阻断阈值 |
tool_config object |
可选值:function_calling_config.mode:AUTO / ANY / NONE / VALIDATED 工具调用配置,控制模型如何选择工具 |
config.thinking_config object |
默认值:thinking_level: medium 可选值:thinking_level:low / medium / high;include_thoughts:true / false 思考配置,控制思考档位与是否返回思考过程 |
config.max_output_tokens integer |
默认值:65536 可选值:1 ~ 1048576 最大输出 token 数,思考与正文共享该上限 |
config.stop_sequences array |
可选值:字符串数组 停止序列数组,命中任一字符串即停止生成 |
config.response_mime_type string |
默认值:text/plain 可选值:text/plain / application/json 响应 MIME 类型,取 application/json 时配合 schema 实现结构化输出 |
config.response_schema object |
可选值:Gemini Schema 对象 结构化输出 schema(Gemini Schema 形式) |
config.response_json_schema object |
可选值:标准 JSON Schema 结构化输出 schema(标准 JSON Schema 形式) |
config.seed integer |
可选值:整数 随机种子,固定后模型尽力返回确定性结果 |
config.routing_config object |
可选值:对象 模型路由配置,用于控制请求在模型版本间的路由策略 |
config.labels object |
可选值:键值对 用户自定义元数据标签,用于请求归类与计费统计 |
config.service_tier string |
可选值:SERVICE_TIER_UNSPECIFIED / SERVICE_TIER_STANDARD / SERVICE_TIER_FLEX / SERVICE_TIER_PRIORITY 服务层级,指定请求的算力优先级 |
config.response_modalities array |
可选值:TEXT 响应模态 |
config.media_resolution string |
可选值:MEDIA_RESOLUTION_LOW / MEDIA_RESOLUTION_MEDIUM / MEDIA_RESOLUTION_HIGH 媒体输入分辨率档位,影响图像与视频的 token 化质量 |
config.continuation_token string |
可选值:字符串 长解码续传令牌,单跳输出中断后携带该令牌重发同一请求续传 |
请求示例
curl -v 'https://www.sagelib.com/gemini/v1beta/models/gemini-4-argon:streamGenerateContent' \
-H "x-goog-api-key: ***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{
"text": "Please analyze the competitive landscape of the new energy vehicle market in 2024, and explain the differentiation strategies and core advantages of the major players."
}
],
"role": "user"
}
],
"model": "gemini-4-argon"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
headers = {
"x-goog-api-key": api_key,
"Content-Type": "application/json",
}
data = {
"contents": [{
"parts": [{
"text": "Please analyze the competitive landscape of the new energy vehicle market in 2024, and explain the differentiation strategies and core advantages of the major players."
}],
"role": "user"
}],
"model": "gemini-4-argon"
}
# 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent";
String jsonRequestBody = """
{
"contents": [
{
"parts": [
{
"text": "Please analyze the competitive landscape of the new energy vehicle market in 2024, and explain the differentiation strategies and core advantages of the major players."
}
],
"role": "user"
}
],
"model": "gemini-4-argon"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-goog-api-key", 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
jsonRequestBody := `
{
"contents": [
{
"parts": [
{
"text": "Please analyze the competitive landscape of the new energy vehicle market in 2024, and explain the differentiation strategies and core advantages of the major players."
}
],
"role": "user"
}
],
"model": "gemini-4-argon"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-goog-api-key", 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent' \
-H "x-goog-api-key: ***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{
"text": "How is the weather in Beijing today? Based on it, tell me whether I need an umbrella when going out; state clearly if the tool is unavailable."
}
],
"role": "user"
}
],
"tools": [
{
"function_declarations": [
{
"name": "get_weather"
}
]
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
headers = {
"x-goog-api-key": api_key,
"Content-Type": "application/json",
}
data = {
"contents": [{
"parts": [{
"text": "How is the weather in Beijing today? Based on it, tell me whether I need an umbrella when going out; state clearly if the tool is unavailable."
}],
"role": "user"
}],
"tools": [{
"function_declarations": [{
"name": "get_weather"
}]
}]
}
# 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent";
String jsonRequestBody = """
{
"contents": [
{
"parts": [
{
"text": "How is the weather in Beijing today? Based on it, tell me whether I need an umbrella when going out; state clearly if the tool is unavailable."
}
],
"role": "user"
}
],
"tools": [
{
"function_declarations": [
{
"name": "get_weather"
}
]
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-goog-api-key", 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
jsonRequestBody := `
{
"contents": [
{
"parts": [
{
"text": "How is the weather in Beijing today? Based on it, tell me whether I need an umbrella when going out; state clearly if the tool is unavailable."
}
],
"role": "user"
}
],
"tools": [
{
"function_declarations": [
{
"name": "get_weather"
}
]
}
]
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-goog-api-key", 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent' \
-H "x-goog-api-key: ***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"parts": [
{
"fileData": {
"mimeType": "image/png",
"fileUri": "${image_url}"
}
},
{
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
],
"role": "user"
}
]
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your API key
url = f"https://www.sagelib.com/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
headers = {
"x-goog-api-key": api_key,
"Content-Type": "application/json",
}
data = {
"contents": [{
"parts": [{
"fileData": {
"mimeType": "image/png",
"fileUri": "${image_url}"
}
}, {
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}],
"role": "user"
}]
}
# 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent";
String jsonRequestBody = """
{
"contents": [
{
"parts": [
{
"fileData": {
"mimeType": "image/png",
"fileUri": "${image_url}"
}
},
{
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
],
"role": "user"
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("x-goog-api-key", 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/gemini/v1beta/models/gemini-4-argon:streamGenerateContent"
jsonRequestBody := `
{
"contents": [
{
"parts": [
{
"fileData": {
"mimeType": "image/png",
"fileUri": "${image_url}"
}
},
{
"text": "Please look at this image carefully and describe the main subject, scene and style details."
}
],
"role": "user"
}
]
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("x-goog-api-key", 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 参数
| 参数名称 | 描述 |
|---|---|
candidates array |
候选结果数组 |
candidates[].content.role string |
可选值:model 固定 model |
candidates[].content.parts array |
输出内容块数组 |
candidates[].content.parts[].text string |
文本输出内容 |
candidates[].content.parts[].functionCall object |
工具调用结果,含 name、args、id,仅在触发工具调用时出现 |
candidates[].content.parts[].thoughtSignature string |
思考签名(base64),非可读文本 |
candidates[].finishReason string |
可选值:STOP 结束原因:STOP 正常结束 |
createTime string |
响应创建时间 |
modelVersion string |
实际服务的模型版本,回带 gemini-4-argon |
responseId string |
响应唯一标识 |
usageMetadata object |
token 用量元数据 |
usageMetadata.promptTokenCount integer |
输入 token 数 |
usageMetadata.candidatesTokenCount integer |
输出 token 数 |
usageMetadata.totalTokenCount integer |
总 token 数 |
usageMetadata.promptTokensDetails array |
输入 token 按模态拆分,含 modality 与 tokenCount |
usageMetadata.candidatesTokensDetails array |
输出 token 按模态拆分 |
usageMetadata.trafficType string |
可选值:ON_DEMAND 流量类型,回带 ON_DEMAND |