curl --request POST \
--url https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}'
import requests
url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload = {
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
const payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload := map[string]interface{}{
"contents": []map[string]interface{}{
{
"role": "user",
"parts": []map[string]interface{}{
{
"text": "你好,介绍一下自己",
},
},
},
},
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
String payload = """
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
$payload = [
"contents" => [
[
"role" => "user",
"parts" => [
[
"text" => "你好,介绍一下自己"
]
]
]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent")
payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
{
"code": 200,
"data": {
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "你好!很高兴能向你介绍我自己。\n\n我是一个大型语言模型,由 Google 训练和开发..."
}
]
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
}
],
"promptFeedback": {
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
]
},
"usageMetadata": {
"promptTokenCount": 4,
"candidatesTokenCount": 611,
"totalTokenCount": 2422,
"thoughtsTokenCount": 1807,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 4
}
]
}
}
{
"error": {
"code": 400,
"message": "无效的请求参数",
"status": "INVALID_ARGUMENT"
}
}
{
"error": {
"code": 401,
"message": "认证失败,请检查 API Key",
"status": "UNAUTHENTICATED"
}
}
{
"error": {
"code": 402,
"message": "余额不足,请充值",
"status": "PAYMENT_REQUIRED"
}
}
{
"error": {
"code": 403,
"message": "没有访问权限",
"status": "PERMISSION_DENIED"
}
}
{
"error": {
"code": 404,
"message": "找不到指定的模型",
"status": "NOT_FOUND"
}
}
{
"error": {
"code": 429,
"message": "请求过于频繁,请稍后重试",
"status": "RESOURCE_EXHAUSTED"
}
}
{
"error": {
"code": 500,
"message": "服务器内部错误",
"status": "INTERNAL"
}
}
{
"error": {
"code": 502,
"message": "网关错误,服务暂时不可用",
"status": "BAD_GATEWAY"
}
}
{
"error": {
"code": 503,
"message": "服务暂时不可用",
"status": "UNAVAILABLE"
}
}
文字系列
Gemini 原生格式
- 使用 Google 原生 API 格式调用 Gemini 模型
- 同步处理模式,实时返回对话内容
- 最简化参数,快速上手
POST
/
v1beta
/
models
/
{model}
:
{method}
curl --request POST \
--url https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}'
import requests
url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload = {
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
const payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload := map[string]interface{}{
"contents": []map[string]interface{}{
{
"role": "user",
"parts": []map[string]interface{}{
{
"text": "你好,介绍一下自己",
},
},
},
},
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
String payload = """
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
$payload = [
"contents" => [
[
"role" => "user",
"parts" => [
[
"text" => "你好,介绍一下自己"
]
]
]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent")
payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
{
"code": 200,
"data": {
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "你好!很高兴能向你介绍我自己。\n\n我是一个大型语言模型,由 Google 训练和开发..."
}
]
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
}
],
"promptFeedback": {
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
]
},
"usageMetadata": {
"promptTokenCount": 4,
"candidatesTokenCount": 611,
"totalTokenCount": 2422,
"thoughtsTokenCount": 1807,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 4
}
]
}
}
{
"error": {
"code": 400,
"message": "无效的请求参数",
"status": "INVALID_ARGUMENT"
}
}
{
"error": {
"code": 401,
"message": "认证失败,请检查 API Key",
"status": "UNAUTHENTICATED"
}
}
{
"error": {
"code": 402,
"message": "余额不足,请充值",
"status": "PAYMENT_REQUIRED"
}
}
{
"error": {
"code": 403,
"message": "没有访问权限",
"status": "PERMISSION_DENIED"
}
}
{
"error": {
"code": 404,
"message": "找不到指定的模型",
"status": "NOT_FOUND"
}
}
{
"error": {
"code": 429,
"message": "请求过于频繁,请稍后重试",
"status": "RESOURCE_EXHAUSTED"
}
}
{
"error": {
"code": 500,
"message": "服务器内部错误",
"status": "INTERNAL"
}
}
{
"error": {
"code": 502,
"message": "网关错误,服务暂时不可用",
"status": "BAD_GATEWAY"
}
}
{
"error": {
"code": 503,
"message": "服务暂时不可用",
"status": "UNAVAILABLE"
}
}
curl --request POST \
--url https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}'
import requests
url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload = {
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
const payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
};
const headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent"
payload := map[string]interface{}{
"contents": []map[string]interface{}{
{
"role": "user",
"parts": []map[string]interface{}{
{
"text": "你好,介绍一下自己",
},
},
},
},
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer <token>")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
public class Main {
public static void main(String[] args) throws Exception {
String url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
String payload = """
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "你好,介绍一下自己"
}
]
}
]
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
<?php
$url = "https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent";
$payload = [
"contents" => [
[
"role" => "user",
"parts" => [
[
"text" => "你好,介绍一下自己"
]
]
]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer <token>",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
require 'net/http'
require 'json'
require 'uri'
url = URI("https://api.apimart.ai/v1beta/models/gemini-2.5-pro:generateContent")
payload = {
contents: [
{
role: "user",
parts: [
{
text: "你好,介绍一下自己"
}
]
}
]
}
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json
response = http.request(request)
puts response.body
{
"code": 200,
"data": {
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "你好!很高兴能向你介绍我自己。\n\n我是一个大型语言模型,由 Google 训练和开发..."
}
]
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
}
],
"promptFeedback": {
"safetyRatings": [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
}
]
]
},
"usageMetadata": {
"promptTokenCount": 4,
"candidatesTokenCount": 611,
"totalTokenCount": 2422,
"thoughtsTokenCount": 1807,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 4
}
]
}
}
{
"error": {
"code": 400,
"message": "无效的请求参数",
"status": "INVALID_ARGUMENT"
}
}
{
"error": {
"code": 401,
"message": "认证失败,请检查 API Key",
"status": "UNAUTHENTICATED"
}
}
{
"error": {
"code": 402,
"message": "余额不足,请充值",
"status": "PAYMENT_REQUIRED"
}
}
{
"error": {
"code": 403,
"message": "没有访问权限",
"status": "PERMISSION_DENIED"
}
}
{
"error": {
"code": 404,
"message": "找不到指定的模型",
"status": "NOT_FOUND"
}
}
{
"error": {
"code": 429,
"message": "请求过于频繁,请稍后重试",
"status": "RESOURCE_EXHAUSTED"
}
}
{
"error": {
"code": 500,
"message": "服务器内部错误",
"status": "INTERNAL"
}
}
{
"error": {
"code": 502,
"message": "网关错误,服务暂时不可用",
"status": "BAD_GATEWAY"
}
}
{
"error": {
"code": 503,
"message": "服务暂时不可用",
"status": "UNAVAILABLE"
}
}
Authorizations
所有接口均需要使用Bearer Token进行认证获取 API Key:访问 API Key 管理页面 获取您的 API Key使用时在请求头中添加:
Authorization: Bearer YOUR_API_KEY
Path Parameters
模型名称示例中使用
gemini-2.5-pro,您可以将其替换为其他支持的 Gemini 模型:gemini-3.5-flash- Gemini 3.5 快速版gemini-3.1-pro-preview- Gemini 3.1 Pro 预览版gemini-3-pro-preview- Gemini 3 Pro 预览版gemini-2.5-pro- Gemini 2.5 专业版
生成方法(快速开始推荐使用
generateContent):generateContent: 等待完整响应后一次性返回streamGenerateContent: 流式返回,逐块实时返回内容
generateContent, streamGenerateContentBody
对话内容列表最少需要1条消息
示例:
显示 contents 对象结构
显示 contents 对象结构
[
{
"role": "user",
"parts": [{ "text": "你好,介绍一下自己" }]
}
]
安全设置(可选)
显示 safetySettings 对象结构
显示 safetySettings 对象结构
Response
候选响应列表
显示 candidates 对象结构
显示 candidates 对象结构
完成原因:
STOP: 正常结束MAX_TOKENS: 达到最大 token 限制SAFETY: 因安全原因停止RECITATION: 因重复内容停止OTHER: 其他原因
候选响应的索引
使用量统计
显示 usageMetadata 属性
显示 usageMetadata 属性
⌘I