curl --request POST \
--url https://api.aihubmax.com/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "杭州今天的天气适合出去玩吗?"
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_weather",
"description": "获取指定城市的当前天气信息",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "温度单位"
}
},
"required": [
"city"
]
}
}
]
}
]
}
'{
"candidates": [
{
"content": {
"parts": [
{
"text": "Hello! How can I help you today?"
}
],
"role": "model"
},
"finishReason": "STOP",
"safetyRatings": [
{
"category": "<string>",
"probability": "<string>"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 25,
"candidatesTokenCount": 150,
"totalTokenCount": 175
}
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "API密钥无效",
"type": "authentication_error"
}
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "访问被拒绝",
"type": "permission_error"
}
}{
"error": {
"message": "请求频率超限",
"type": "rate_limit_error"
}
}{
"error": {
"message": "服务器内部错误",
"type": "server_error"
}
}调用工具
Gemini 格式 - 调用工具内容生成
- 适用于所有兼容 Gemini 原生格式模型的通用 generateContent API(含工具调用)
- 工具调用:支持函数声明,模型可调用定义的函数
- 多模态输入:支持文本 + 图像/音频/视频混合输入
- 生成配置:通过 generationConfig 控制温度、topP、topK、maxOutputTokens
- 安全设置:可配置内容安全阈值
- 支持流式和非流式响应
POST
/
v1beta
/
models
/
{model}
:generateContent
curl --request POST \
--url https://api.aihubmax.com/v1beta/models/{model}:generateContent \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "杭州今天的天气适合出去玩吗?"
}
]
}
],
"tools": [
{
"functionDeclarations": [
{
"name": "get_weather",
"description": "获取指定城市的当前天气信息",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "温度单位"
}
},
"required": [
"city"
]
}
}
]
}
]
}
'{
"candidates": [
{
"content": {
"parts": [
{
"text": "Hello! How can I help you today?"
}
],
"role": "model"
},
"finishReason": "STOP",
"safetyRatings": [
{
"category": "<string>",
"probability": "<string>"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 25,
"candidatesTokenCount": 150,
"totalTokenCount": 175
}
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "API密钥无效",
"type": "authentication_error"
}
}{
"error": {
"message": "请求参数无效",
"type": "invalid_request_error"
}
}{
"error": {
"message": "访问被拒绝",
"type": "permission_error"
}
}{
"error": {
"message": "请求频率超限",
"type": "rate_limit_error"
}
}{
"error": {
"message": "服务器内部错误",
"type": "server_error"
}
}授权
所有接口均需要使用Bearer Token进行认证
使用时在请求头中添加:
Authorization: Bearer YOUR_API_KEY
路径参数
模型名称,如 gemini-2.5-flash
示例:
"gemini-2.5-flash"
请求体
application/json
⌘I