Gemini native API
Use generateContent and native content structures with compatible Gemini models.
Configure and call
Confirm that the line supports Gemini native requests and set IROUTER_API_KEY from the API overview. Replace <model-id> in the path with the catalog's identifier for this endpoint, without duplicating models/.
curl --fail-with-body 'https://gateway.irouter.io/v1beta/models/<model-id>:generateContent' \
-H "x-goog-api-key: $IROUTER_API_KEY" \
-H 'Content-Type: application/json' \
--data '{"contents":[{"role":"user","parts":[{"text":"Reply with a short greeting."}]}]}'Native requests use contents and parts, not messages. The path uses /v1beta, not the OpenAI SDK /v1 prefix.
Read the response
Text appears in the text parts of each candidate's content.parts. Check finish reasons and safety feedback. A response without text candidates is not necessarily a successful empty answer. Usage is usually in usageMetadata.
Streaming and boundaries
For SSE, use :streamGenerateContent?alt=sse on the same model path and parse events. Keep the key in the x-goog-api-key header.
:countTokens is not implemented in the gateway version covered here. A model's appearance in the unified catalog does not establish native-protocol support. For 404 or model errors, verify the model path, line, and protocol, then follow troubleshooting.
Native field reference: Google generateContent.