generateContent REST
contract verbatim, so the google-generativeai Python SDK and the
@google/generative-ai JS SDK work unchanged — flip the base URL and
your apiKey. Cross-vendor models (Claude, GPT, DeepSeek, Doubao) are
translated to Gemini shape under the hood.
When to use
Pick this endpoint when you want:- Drop-in for
google-generativeai/ Gemini SDK clients - Gemini-only features like
responseSchemawith the Gemini-flavoured JSON schema, orsafetySettings - Code paths already structured around
contents[].parts[](different from OpenAI / Anthropicmessages)
/v1/messages; for OpenAI shape, /chat/completions.
Request
{model} in the path is the model slug (e.g. gemini-3-1-pro). For streaming, use the sibling :streamGenerateContent path — see Streaming below.
Headers
| Header | Required | Notes |
|---|---|---|
x-goog-api-key | yes | Your ByteSpike key. (Authorization: Bearer … also accepted.) |
content-type | yes | application/json. |
Body
| Field | Type | Required | Notes |
|---|---|---|---|
contents | array | yes | Conversation turns. Each item has role (user / model) + parts[]. |
systemInstruction | object | no | {"parts":[{"text": "…"}]} — Gemini’s system prompt slot. |
generationConfig.maxOutputTokens | integer | no | Hard cap on response length. |
generationConfig.temperature | number | no | 0.0–2.0. |
generationConfig.topP | number | no | Nucleus sampling. |
generationConfig.topK | integer | no | Top-K sampling. |
generationConfig.stopSequences | string[] | no | Custom stop tokens. |
generationConfig.responseMimeType | string | no | application/json to force JSON. |
generationConfig.responseSchema | object | no | Gemini-shape JSON schema constraint. |
tools | array | no | Function declarations — see Tool calling. |
toolConfig | object | no | {"functionCallingConfig": {"mode": "ANY"|"AUTO"|"NONE"}}. |
safetySettings | array | no | Per-category thresholds (HARM_CATEGORY_HARASSMENT, etc.). Forwarded to the Gemini model. |
Response
Response fields
| Field | Type | Notes |
|---|---|---|
candidates[].content.parts[] | array | Text and/or functionCall parts. |
candidates[].finishReason | string | STOP, MAX_TOKENS, SAFETY, RECITATION. |
candidates[].safetyRatings | array | Gemini’s content-safety scores. |
usageMetadata.promptTokenCount | integer | Tokens billed for input. |
usageMetadata.candidatesTokenCount | integer | Tokens billed for output. |
Accounting headers
Same envelope as every other endpoint:Streaming
Use the sibling path:streamGenerateContent:
alt=sse) with each frame carrying a partial candidates payload:
alt=sse, the response is a JSON array of frames — the SDK default.)
Tool calling
Gemini’stools[].functionDeclarations[] shape. Round-trip via two requests:
Round 1 — tool offered
functionCall part:
args is a structured object here, not a JSON string (unlike OpenAI’s tool_calls.arguments).
Round 2 — tool result returned
Multimodal (image / audio parts)
Inline a base64-encoded image as a part on the user message:fileData.fileUri (the file must be publicly reachable over HTTPS). Audio (audio/wav, audio/mp3) and video (video/mp4) parts work the same way on multimodal-capable models.
Cross-model routing
The{model} path segment accepts any ByteSpike catalog model — the gateway translates the Gemini shape to each model’s native protocol:
responseSchemaconstraint requires the model to support structured outputs; otherwise returns 400unsupported_feature.safetySettingsare only honored on Gemini models — silently ignored on Claude / GPT / DeepSeek (those have their own safety stacks).usageMetadatafield names are Gemini-shape regardless of the model.
GET /v1/models. Pricing per model: bytespike.ai/pricing.
Errors
All non-2xx responses are free. Body shape matches Gemini’s error envelope:| Status | error.status | Trigger |
|---|---|---|
| 400 | INVALID_ARGUMENT | Body validation failed. Message identifies the field. |
| 400 | INVALID_ARGUMENT (msg unsupported_model) | Model slug not in scope. |
| 400 | INVALID_ARGUMENT (msg unsupported_feature) | E.g. responseSchema on a non-structured-output model. |
| 401 | UNAUTHENTICATED | Missing / revoked key. |
| 402 | FAILED_PRECONDITION (msg insufficient_credits) | Wallet exhausted. |
| 403 | PERMISSION_DENIED | Scope denied, IP allowlist, model gated. |
| 404 | NOT_FOUND | Path typo or unknown model id. |
| 429 | RESOURCE_EXHAUSTED | Tier rate-limit. Backoff per x-ratelimit-reset-*. |
| 5xx | INTERNAL / UNAVAILABLE | Upstream provider issue. Free + automatic retry envelope. |
SDK example
google-generativeai Python SDK, base URL pointed at ByteSpike: