Send native Gemini messages through generateContent.
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 |
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": "Introduce yourself in one sentence."
}
]
}
]
}'
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[] | Content blocks returned by the model |
| candidates[].finishReason | Reason generation stopped |
| usageMetadata | Usage metadata |
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.
Streaming
Change the path to /v1beta/models/{model}:streamGenerateContent?alt=sse and keep the native Gemini request body. Add -N to curl and parse SSE events individually.