Attach images, audio, video, or PDFs to text messages for understanding by a Gemini model that supports the corresponding modalities.
Request
| Item | Description |
|---|---|
| Method | POST |
| Path | /v1beta/models/{model}:generateContent |
| Gateway URL | https://ailink.nativex.com |
| Authentication | Authorization: Bearer sk-xxxx; replace the placeholder with your API Key |
| Request format | application/json |
Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.
Parameters
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
model |
Path | string | Yes | Gemini model name |
contents |
Body | object[] | Yes | Message array. Each message contains role and parts; common roles are user and model. |
systemInstruction |
Body | object | No | System instructions, supplied through parts |
generationConfig |
Body | object | No | Generation settings, such as temperature, topP, and maxOutputTokens |
safetySettings |
Body | object[] | No | Safety settings supported by the model |
tools |
Body | object[] | No | Tool definitions |
contents[].parts[].inlineData |
Body | object | No | mimeType and Base64-encoded data |
contents[].parts[].fileData |
Body | object | No | mimeType and an accessible fileUri; use this or inlineData as appropriate |
Replace the example media URL. Prefer URLs publicly accessible to the upstream service. Private URIs uploaded through the Gemini File API are subject to upstream account permissions.
Example
curl -X POST 'https://ailink.nativex.com/v1beta/models/MODEL_ID:generateContent' \
-H 'Authorization: Bearer sk-xxxx' \
-H 'Content-Type: application/json' \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Describe this image."
},
{
"fileData": {
"mimeType": "image/png",
"fileUri": "https://example.com/input.png"
}
}
]
}
]
}'
Response
The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello! How can I help you?"
}
]
},
"finishReason": "STOP"
}
]
}
| Field or result | Description |
|---|---|
| candidates[].content.parts[].text | The model's analysis of the media |
Error handling
For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.