跳转到主要内容
POST
/
v1beta
/
models
/
{model}
:generateContent
生成内容
curl --request POST \
  --url https://www.anyfast.ai/v1beta/models/{model}:generateContent \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "你好,Gemini!"
        }
      ]
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "<string>"
      }
    ]
  },
  "generationConfig": {
    "temperature": 1,
    "topP": 0.5,
    "topK": 123,
    "maxOutputTokens": 123,
    "stopSequences": [
      "<string>"
    ],
    "responseMimeType": "text/plain",
    "responseSchema": {}
  },
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "<string>",
          "description": "<string>",
          "parameters": {}
        }
      ]
    }
  ],
  "toolConfig": {
    "functionCallingConfig": {
      "mode": "AUTO",
      "allowedFunctionNames": [
        "<string>"
      ]
    }
  },
  "safetySettings": [
    {
      "category": "HARM_CATEGORY_HARASSMENT",
      "threshold": "BLOCK_NONE"
    }
  ]
}
'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "<string>"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 123,
      "safetyRatings": [
        {
          "category": "<string>",
          "probability": "<string>"
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 123,
    "candidatesTokenCount": 123,
    "totalTokenCount": 123
  },
  "modelVersion": "<string>"
}

授权

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

路径参数

model
enum<string>
必填

用于生成的模型名称。

可用选项:
gemini-3.1-pro-preview,
gemini-3.1-flash-image-preview,
gemini-3.1-flash-lite-preview,
gemini-3-pro-preview,
gemini-3-pro-image-preview,
gemini-3-flash-preview,
gemini-2.5-pro,
gemini-2.5-flash,
gemini-2.5-flash-lite,
gemini-2.0-flash

请求体

application/json
contents
object[]
必填

与模型的当前对话内容。

Minimum array length: 1
示例:
[
  {
    "role": "user",
    "parts": [{ "text": "你好,Gemini!" }]
  }
]
systemInstruction
object

开发者设置的系统指令。

generationConfig
object

模型生成和输出的配置选项。

tools
object[]

模型可用于生成响应的工具列表。

toolConfig
object

请求中指定的任何工具的工具配置。

safetySettings
object[]

用于阻止不安全内容的安全设置列表。

响应

内容生成成功

candidates
object[]
usageMetadata
object
modelVersion
string