官方文档:https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn
POST
/v1beta/models/gemini-2.5-pro:generateContent格式化输出
API Key application/json
请求示例
curl -X POST https://top.qingyuntop.ai/v1beta/models/gemini-2.5-pro:generateContent \
-H "Authorization: Bearer ${QINGYUN_TOP_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "List a few popular cookie recipes, and include the amounts of ingredients."
}
]
}
],
"generationConfig": {
"responseMimeType": "application/json",
"responseSchema": {
"type": "ARRAY",
"items": {
"type": "OBJECT",
"properties": {
"recipeName": {
"type": "STRING"
},
"ingredients": {
"type": "ARRAY",
"items": {
"type": "STRING"
}
}
},
"propertyOrdering": [
"recipeName",
"ingredients"
]
}
}
}
}'请求参数
| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|---|
key | Query | string | 是 | - | {{YOUR_API_KEY}} |
Content-Type | Header | string | 是 | - | application/json |
contents | JSON body | array<object> | 是 | - | - |
contents[].parts | JSON body | array<object> | 否 | - | - |
contents[].parts[].text | JSON body | string | 否 | - | - |
contents[].parts[].inline_data | JSON body | object | 否 | - | - |
contents[].parts[].inline_data.mime_type | JSON body | string | 是 | - | - |
contents[].parts[].inline_data.data | JSON body | string | 是 | - | - |
generationConfig | JSON body | object | 是 | - | - |
generationConfig.responseModalities | JSON body | array<string> | 是 | - | - |
返回响应 (200)
此部分没有定义参数。
来源原始接口定义(用于追溯)
以下内容来自 Apifox 快照,可能包含兼容层字段或旧示例;公开调用请以本页的协议说明和当前模型列表为准。
{
"id": 497673453,
"name": "格式化输出",
"type": "http",
"serverId": "",
"preProcessors": [],
"postProcessors": [],
"inheritPreProcessors": {},
"inheritPostProcessors": {},
"description": "官方文档:https://ai.google.dev/gemini-api/docs/structured-output?hl=zh-cn",
"operationId": "",
"sourceUrl": "",
"method": "post",
"path": "/v1beta/models/gemini-2.5-pro:generateContent",
"tags": [],
"status": 1,
"requestBody": {
"type": "application/json",
"parameters": [],
"jsonSchema": {
"type": "object",
"properties": {
"contents": {
"type": "array",
"items": {
"type": "object",
"properties": {
"parts": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string"
},
"inline_data": {
"type": "object",
"properties": {
"mime_type": {
"type": "string"
},
"data": {
"type": "string"
}
},
"required": [
"mime_type",
"data"
],
"x-apifox-orders": [
"mime_type",
"data"
]
}
},
"x-apifox-orders": [
"text",
"inline_data"
]
}
}
},
"x-apifox-orders": [
"parts"
]
}
},
"generationConfig": {
"type": "object",
"properties": {
"responseModalities": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"responseModalities"
],
"x-apifox-orders": [
"responseModalities"
]
}
},
"required": [
"contents",
"generationConfig"
],
"x-apifox-orders": [
"contents",
"generationConfig"
]
},
"examples": [
{
"mediaType": "application/json",
"value": "{\n \"contents\": [\n {\n \"role\": \"user\",\n \"parts\": [\n {\n \"text\": \"List a few popular cookie recipes, and include the amounts of ingredients.\"\n }\n ]\n }\n ],\n \"generationConfig\": {\n \"responseMimeType\": \"application/json\",\n \"responseSchema\": {\n \"type\": \"ARRAY\",\n \"items\": {\n \"type\": \"OBJECT\",\n \"properties\": {\n \"recipeName\": {\n \"type\": \"STRING\"\n },\n \"ingredients\": {\n \"type\": \"ARRAY\",\n \"items\": {\n \"type\": \"STRING\"\n }\n }\n },\n \"propertyOrdering\": [\n \"recipeName\",\n \"ingredients\"\n ]\n }\n }\n }\n}",
"name": "示例"
}
],
"mediaType": "",
"oasExtensions": "",
"required": false,
"additionalContentTypes": []
},
"parameters": {
"path": [],
"query": [
{
"id": "fNkAG1L7Ct",
"name": "key",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "{{YOUR_API_KEY}}"
}
],
"cookie": [],
"header": [
{
"id": "DxzZ9GHHTb",
"name": "Content-Type",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "application/json"
}
]
},
"commonParameters": {
"query": [],
"body": [],
"cookie": [],
"header": []
},
"auth": {},
"responses": [
{
"id": 177239631,
"name": "成功",
"code": 200,
"contentType": "json",
"jsonSchema": {
"type": "object",
"properties": {},
"x-apifox-orders": []
},
"itemSchema": {},
"description": "",
"mediaType": "",
"headers": [],
"oasExtensions": ""
}
],
"responseExamples": [],
"codeSamples": [],
"projectId": 8662722,
"moduleId": 8310462,
"folderId": 92749360,
"ordering": 54,
"responsibleId": 0,
"commonResponseStatus": {},
"advancedSettings": {
"disabledSystemHeaders": {}
},
"customApiFields": {},
"oasExtensions": "",
"mockScript": {},
"createdAt": "2026-08-05T14:40:23.000Z",
"updatedAt": "2026-08-06T12:15:55.000Z",
"creatorId": 2863449,
"editorId": 2863449,
"creatorUserId": 2863449,
"editorUserId": 2863449,
"responseChildren": [],
"visibility": "INHERITED",
"securityScheme": {},
"callbacks": ""
}