Generate text with a Gemini-compatible request and response format.
Description
This endpoint accepts Gemini-style request bodies and forwards them through APIFreeās unified model platform. Use it when your client already expects Gemini-native payloads and response semantics.
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Authorization | string | Yes | Bearer token in the format Bearer YOUR_API_KEY. |
Content-Type | string | Yes | Must be application/json. |
Request body parameters
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID to use for generation. |
contents | array | Yes | Gemini conversation content payload. |
system_instruction | object | No | Optional system instruction object. |
generationConfig | object | No | Optional generation configuration. |
safetySettings | array | No | Optional Gemini safety settings. |
tools | array | No | Optional tool declarations. |
stream | boolean | No | Whether to return a streaming response when supported. |
Supported models
| Model |
|---|
gemini-2.5-pro |
gemini-2.5-flash |
gemini-2.5-flash-lite |
gemini-3-pro-preview |
gemini-3.1-pro-preview |
gemini-3-flash-preview |
Example request
curl https://api.apifree.ai/google/gemini \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"contents": [
{
"role": "user",
"parts": [
{
"text": "Explain model routing in a unified AI gateway."
}
]
}
]
}'Response schema
A successful response returns the Gemini-style upstream payload. Typical fields include:
| Field | Type | Description |
|---|---|---|
candidates | array | Candidate outputs returned by the model. |
usageMetadata | object | Token usage information. |
modelVersion | string | Upstream model version when available. |
Example response:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "Model routing lets a gateway choose the most appropriate upstream provider for a request while preserving one stable API for the client."
}
],
"role": "model"
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 14,
"candidatesTokenCount": 24,
"totalTokenCount": 38
}
}
Streaming
When streaming is enabled, the endpoint returns the Gemini-compatible streamed output format from the upstream protocol.
Errors
Errors are returned as JSON error objects. Typical cases include:
- Missing or invalid
model - Invalid JSON request body
- Authentication failure
- Upstream request failure