Skip to navigation

Gemini native

Call Gemini 4 Argon, Gemini 3.8 Flash and Gemini 3.1 Pro with Gemini generateContent requests and one BeatAPI key.

  • POST /v1beta/models/{model}:generateContent, and :streamGenerateContent?alt=sse for streaming, for every current Gemini model.
  • Text and image input, text output, streaming, function calling and thinking.
  • Send the key in the x-goog-api-key header or as a Bearer token.
  • The model is in the URL, not in the body.

Use https://direct.beatapi.io as the base URL for text requests: it is not subject to Cloudflare’s 100-second limit, so a long non-streaming request is not cut off. https://api.beatapi.io also works and is the fallback if direct.beatapi.io is unreachable from your network. The key, models and prices are the same on both. Image and video APIs use https://api.beatapi.io only.

POST/v1beta/models/{model}:generateContentTry it

Opens this endpoint in the API Explorer. Enter your BeatAPI API key and send: the call is real and is billed to your own balance.

Models

Put one of these IDs in the URL, in place of {model}.

Model IDContext (tokens)Max output (tokens)PositioningInput, USD per 1M tokensOutput, USD per 1M tokens
gemini-4-argon—1,000,000Google’s Gemini 4 flagship model, with an output limit of up to 1M tokens.$1.00$5.00
gemini-3.8-flash——Google’s most intelligent Flash model, engineered for long-horizon software engineering, autonomous agents, and complex enterprise workflows$0.375$1.875
gemini-3.1-pro-preview1,048,57665,536Reasoning-first Gemini preview for agentic coding and complex problem solving$1.00$6.00
  • Prices are the base tier, discount already applied. A long-context tier, cached-input rates and cache writes are not in this table; see the price table.
  • — means the catalogue does not publish the number.

Older IDs of this family still work and are listed on Legacy models.

Quick start

Keep the key in BEATAPI_API_KEY and never put it in browser code. The model ID goes in the URL, so the body has no model field. These are request examples, not recorded model outputs.

Read the answer from candidates[0].content.parts[0].text, then check candidates[0].finishReason and usageMetadata. An HTTP 200 alone does not prove the answer satisfies your task: validate it in your application. Text requests return directly; do not poll /v1/tasks for them.

curl --request POST \
--url https://direct.beatapi.io/v1beta/models/gemini-3.8-flash:generateContent \
--header "x-goog-api-key: $BEATAPI_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Design a resilient webhook retry strategy for a payments API."
}
]
}
]
}'

Endpoint and authentication

POST https://direct.beatapi.io/v1beta/models/{model}:generateContent

x-goog-api-key string Required

Your BeatAPI key in the x-goog-api-key header. Authorization: Bearer <BEATAPI_API_KEY> is also accepted.

For streaming, call POST /v1beta/models/{model}:streamGenerateContent?alt=sse. The key goes in the x-goog-api-key header or in Authorization: Bearer <key>; both work.

:countTokens is not available and returns 404.

Request parameters

These are the fields that take effect. Other Gemini fields are accepted in the request but have no effect: generationConfig.thinkingConfig, generationConfig.responseMimeType, generationConfig.responseSchema, generationConfig.seed, safetySettings, toolConfig and cachedContent. Do not rely on them.

contents object[] Required

The conversation, oldest turn first. Each item has a role (user or model) and parts. A part is text, inlineData (mimeType and base64 data), fileData (mimeType and fileUri), functionCall or functionResponse.

  • Image input is supported by every current Gemini model; use inlineData, or fileData with an image URL. For other media, test your file type before you depend on it.
  • An empty or missing contents is 400 bad_request.

Example

[
{
"role": "user",
"parts": [
{ "text": "What is in this image?" },
{ "inlineData": { "mimeType": "image/png", "data": "<base64>" } }
]
}
]

systemInstruction object Optional

System prompt, as { "parts": [{ "text": "..." }] }. Only text parts are used.

Example

{
"parts": [{ "text": "Answer in one short paragraph." }]
}

generationConfig object Optional

Generation options. These subfields take effect: maxOutputTokens, temperature, topP, topK, stopSequences and candidateCount.

Example

{
"temperature": 0.7,
"topP": 0.95,
"maxOutputTokens": 2048,
"stopSequences": ["END"]
}

generationConfig.maxOutputTokens integer Optional

Upper bound on the generated tokens, thinking included.

  • The largest accepted value is 1,073,741,823; a larger value is 400 bad_request. Keep it at or below the max output of the model in the table above.
  • Gemini models think by default, and thinking tokens are billed as output and count toward this limit. A small value can be used up by thinking, leaving an empty answer with finishReason: "MAX_TOKENS". Budget at least 1,000 tokens for a short answer.
  • maxOutputTokens is also used to estimate how much balance a request needs. A very large value can be refused with 402 insufficient_credits even when the real output would be small. Set it to what you need.

generationConfig.temperature number Optional

Sampling temperature.

generationConfig.topP number Optional

Nucleus sampling. A value of 0 is ignored.

generationConfig.topK integer Optional

Top-K sampling. A value of 0 is ignored.

generationConfig.stopSequences string[] Optional

Strings that stop generation. At most 4 are used.

generationConfig.candidateCount integer Optional

Number of candidates to return. Leave it unset unless you need more than one.

tools object[] Optional

Function declarations the model may call, as [{ "functionDeclarations": [...] }]. Each declaration has a name, a description and parameters (JSON Schema). A call comes back as a functionCall part; return the result as a functionResponse part in the next user turn.

  • Only functionDeclarations are used. Built-in tools such as googleSearch and codeExecution are ignored.

Example

[
{
"functionDeclarations": [
{
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
]
}
]

Response

A non-streaming call returns one JSON object. This is an abbreviated example.

{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Retry with exponential backoff and jitter, and make every handler idempotent."
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 19,
"candidatesTokenCount": 16,
"totalTokenCount": 120,
"thoughtsTokenCount": 85
}
}

Response fields

FieldTypeDescription
candidates[].content.parts[].textstringThe answer text.
candidates[].content.parts[].functionCallobjectA tool call, with name and args.
candidates[].finishReasonstringSTOP for a complete answer or a tool call, MAX_TOKENS when maxOutputTokens was reached, SAFETY when the answer was filtered.
usageMetadata.promptTokenCountintegerInput tokens.
usageMetadata.candidatesTokenCountintegerOutput tokens of the visible answer.
usageMetadata.thoughtsTokenCountintegerThinking tokens. They are billed as output. The thinking text itself is not returned.
usageMetadata.totalTokenCountintegerAll tokens of the call.

Streaming

Call :streamGenerateContent?alt=sse. Every event is a line data: {...} holding a candidates object, in the same shape as a non-streaming answer.

  • The last event carries finishReason, for example "STOP".
  • The response is text/event-stream. A failure before the model is called is returned as a normal JSON error with an HTTP status, not as a stream event.
  • Set explicit timeouts and reconnect a streamed response safely.
data: {"candidates":[{"content":{"role":"model","parts":[{"text":"Retry"}]},"index":0}]}
data: {"candidates":[{"content":{"role":"model","parts":[{"text":" with backoff"}]},"finishReason":"STOP","index":0}],"usageMetadata":{"promptTokenCount":19,"candidatesTokenCount":16,"totalTokenCount":120,"thoughtsTokenCount":85}}

Errors

Error or symptomCauseFix
400: contents is requiredcontents is empty or absent.Send at least one turn in contents.
400: maxOutputTokens is invalidgenerationConfig.maxOutputTokens is above 1,073,741,823.Lower it to what you need.
402 insufficient_creditsBalance below the price of the request, often because maxOutputTokens is very large.Top up, or lower maxOutputTokens.
403 forbiddenThe account is on free credit and the model is not on the free list, or the model is outside the key’s group.Top up, use a free model, or use a key whose group can reach the model.
404 not_foundUnknown model ID, not enabled for this key, or the :countTokens action.List the enabled models with GET /v1/models.
429 rate_limit_exceededAccount or free-model limit reached.Wait Retry-After, then retry.
200 with finishReason: "MAX_TOKENS" and no textThinking used up maxOutputTokens before the answer was written.Raise generationConfig.maxOutputTokens; at least 1,000 for a short answer.

HTTP errors at a glance

Errors on the Gemini-native endpoint have one shape, {"error": {"message", "type": "beatapi_error", "code"}}: the code is in error.code, the request id ends message, and there is no retryable field. See Errors.

HTTP statusCodeWhat to do
400bad_request, content_policy_violationFix the request or the input; do not resend it unchanged.
401missing_api_key, invalid_api_keyCheck the key. Do not retry.
402insufficient_creditsTop up, or raise the key’s limit. A very large max_tokens can trigger it.
403forbiddenThe model is outside the key’s group or IP allowlist, or free credit cannot call this model.
404not_foundUnknown model: list the enabled ones with GET /v1/models.
429rate_limit_exceededWait Retry-After or retry_after_seconds, then retry with backoff.
500internal_error, temporary_errorRetry once or twice with backoff.
503model_unavailable, upstream_timeout, temporary_errorRetry with backoff, or use another model.

Full code table and retry policy: Errors.

Notes

  • Gemini models also answer on Chat Completions, Responses and Anthropic Messages. See the other Gemini pages.
  • Thinking tokens are billed as output tokens. Budget output for thinking plus the answer, not just the answer.
  • Keep API keys on trusted servers, log the response request ID, and retry only 429, 500 and 503.

Authentication

AuthorizationBearer

Send your API key as Authorization: Bearer <BEATAPI_API_KEY>.

Path parameters

modelenumRequired
Allowed values:

Request

This endpoint expects an object.
contentslist of objectsRequired

The conversation, oldest turn first. Each item has a role (user or model) and parts. A part is text, inlineData (mimeType and base64 data), fileData (mimeType and fileUri), functionCall or functionResponse.

Image input is supported by every current Gemini model; use inlineData, or fileData with an image URL. For other media, test your file type before you depend on it.

An empty or missing contents is 400 bad_request.

systemInstructionobjectOptional

System prompt, as { "parts": [{ "text": "..." }] }. Only text parts are used.

generationConfigobjectOptional

Generation options. These subfields take effect: maxOutputTokens, temperature, topP, topK, stopSequences and candidateCount.

toolslist of objectsOptional

Function declarations the model may call, as [{ "functionDeclarations": [...] }]. Each declaration has a name, a description and parameters (JSON Schema). A call comes back as a functionCall part; return the result as a functionResponse part in the next user turn.

Only functionDeclarations are used. Built-in tools such as googleSearch and codeExecution are ignored.

Response

A non-streaming call returns one JSON object. This is an abbreviated example.

candidateslist of objectsOptional
usageMetadataobjectOptional

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
429
Too Many Requests Error
500
Internal Server Error
503
Service Unavailable Error