APIFree
APIFree
Text Generation

POST /google/gemini

Google Gemini-style text generation endpoint.

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

NameTypeRequiredDescription
AuthorizationstringYesBearer token in the format Bearer YOUR_API_KEY.
Content-TypestringYesMust be application/json.

Request body parameters

NameTypeRequiredDescription
modelstringYesModel ID to use for generation.
contentsarrayYesGemini conversation content payload.
system_instructionobjectNoOptional system instruction object.
generationConfigobjectNoOptional generation configuration.
safetySettingsarrayNoOptional Gemini safety settings.
toolsarrayNoOptional tool declarations.
streambooleanNoWhether 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:

FieldTypeDescription
candidatesarrayCandidate outputs returned by the model.
usageMetadataobjectToken usage information.
modelVersionstringUpstream 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