Skip to main content

Gemini wire format

The native JSON of the Gemini Interactions API, as Freyja speaks it. This page exists so you do not have to read Google's documentation to understand what is going over the wire, or to debug a Error::Api body.

Everything here was verified against the live endpoint at Api-Revision: 2026-05-20. Where behavior was surprising, it is called out.

Endpoint​

POST https://generativelanguage.googleapis.com/v1beta/interactions
x-goog-api-key: <key>
Api-Revision: 2026-05-20
Content-Type: application/json

The Api-Revision header selects the API generation. It is what puts the endpoint in steps mode, described below.

Streaming uses the same path with ?alt=sse appended:

POST https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse

That query parameter is what actually selects SSE framing on this API; "stream": true in the body alone is not enough. Freyja appends it for Client::stream() and never for generate(). See Streaming.

Request body​

{
"model": "gemini-3.5-flash",
"input": "...",
"system_instruction": "Be concise",
"generation_config": {
"max_output_tokens": 512, "temperature": 0.2, "top_p": 0.9,
"thinking_level": "low", "tool_choice": "any"
},
"response_format": { "type": "object", "properties": {}, "required": [] },
"tools": [ { "type": "function", "name": "add", "description": "...", "parameters": {} } ],
"labels": { "trace": "abc" },
"previous_interaction_id": "v1_..."
}

Only model and input are required. Freyja omits every unset field rather than sending null.

The request also carries stream, which generate() leaves unset and which is therefore omitted rather than sent as false. Every body on this page is byte-accurate for a generate() call.

Note the naming: system_instruction rather than a system turn, max_output_tokens rather than max_tokens, and previous_interaction_id rather than previous_response_id.

Two shapes here are unlike the other three dialects, and the endpoint enforces both by name rather than ignoring what it does not recognise.

Sampling, reasoning, and tool controls nest. max_output_tokens, temperature, top_p, thinking_level, and tool_choice live inside generation_config. Sent loose they are rejected, Unknown parameter 'temperature', and so is an unknown key inside the object, which is how you can tell the validation is real rather than tolerant.

thinking_level is where reasoning effort goes, and it takes four values by name:

The value 'none' is not supported for 'thinking_level'.
Supported values: 'minimal', 'low', 'medium', 'high'.

Freyja sends all six portable levels, lowercase, and the endpoint rejects three of them. It does not refuse them itself: the field exists, so which values it takes is this deployment's answer to give. minimal is unreachable, having no portable level to map from.

response_format is the schema, not a wrapper around one. Its type takes JSON Schema type names, and says so when given anything else:

The value 'json_schema' is not supported for 'type' at 'response_format'.
Supported values: 'boolean', 'video', 'audio', 'integer', 'number', 'image',
'array', 'object', 'text', 'string'.

So a JSON-schema request puts the schema straight into the field, and name and strict have nowhere to go, dropped, as they are on Anthropic. ResponseFormat::JsonObject becomes {"type": "object"}.

labels carries the neutral metadata field, and the public endpoint declines it: "The parameter 'labels' is not available on the Gemini API but it is available on the Gemini Enterprise Agent Platform." Freyja sends it anyway. The field is part of this format; a deployment gating it is the deployment's business, and its message names where the field does work.

Input takes two shapes​

A bare string​

For a single plain text user turn, input is just a string:

{ "model": "gemini-3.5-flash", "input": "What is 20 + 22?" }

Freyja uses this automatically when the conversation is one text-only user message.

A step list​

Anything longer is an array of steps, not turns. This is the part most likely to trip you up.

{
"input": [
{ "type": "user_input", "content": [ { "type": "text", "text": "What is 20 + 22?" } ] },
{ "type": "thought", "signature": "EvACCu0CARFNMg..." },
{ "type": "function_call", "id": "mbbykw8q", "name": "add", "arguments": { "a": 20, "b": 22 } },
{ "type": "function_result", "call_id": "mbbykw8q", "name": "add", "result": "42" },
{ "type": "model_output", "content": [ { "type": "text", "text": "The answer is 42." } ] }
]
}

Each step is a flat object with a type. There is no role field, the step type carries that meaning: user_input for the user, model_output for the model.

The older turn-based shape is rejected. Sending [{"role": "user", "content": [...]}] returns:

When using the steps-based API version, use step_list input format instead of turn_list.

If you find Gemini examples online using role and parts, they target the older generateContent endpoint, not this one.

Step types accepted in input​

The API reports the full set when you send an invalid one:

transcription, document, google_search_result, google_search_call, function_result,
google_maps_result, text, file_search_call, video, playback_awaiting,
url_context_result, retrieval_result, code_execution_call, retrieval_call,
url_context_call, elicitation_call, file_search_result, model_output,
code_execution_result, function_call, user_input, mcp_server_tool_result,
compaction, audio, audio_truncation, google_maps_call, elicitation_result,
playback_interruption, content, mcp_server_tool_call, image, thought,
playback_complete

Freyja emits five of these: user_input, model_output, function_call, function_result, and whatever opaque steps it replays, in practice thought.

Content part types​

Inside user_input and model_output, content is an array of parts:

{ "type": "text", "text": "hello" }
{ "type": "image", "uri": "https://example.com/cat.png" }
{ "type": "document", "data": "JVBER...", "mime_type": "application/pdf" }
{ "type": "document", "uri": "https://example.com/contract.pdf", "mime_type": "application/pdf" }
{ "type": "audio", "data": "UklGR...", "mime_type": "audio/wav" }

A file's bytes go as data with their mime_type, since a data URI in uri is refused as an unsupported file URI. A link goes as uri, and Freyja adds the mime_type when the link's extension names one, because without it the endpoint trusts the type the link's server reports.

The accepted part types are text, image, audio, video, document, thought, function_call, function_result, and the various search, maps, code execution, file search, url context, and MCP result types.

Tool calling​

Declaring tools​

"tools": [
{
"type": "function",
"name": "add",
"description": "adds two numbers together",
"parameters": {
"type": "object",
"properties": { "a": { "type": "integer" }, "b": { "type": "integer" } },
"required": ["a", "b"]
}
}
]

The call, as returned​

{ "type": "function_call", "id": "mbbykw8q", "name": "add", "arguments": { "a": 20, "b": 22 } }

arguments is a structured object, not a JSON string. Freyja stringifies it so OutputContent::ToolCall::arguments behaves the same across providers.

The result, as sent back​

{ "type": "function_result", "call_id": "mbbykw8q", "name": "add", "result": "42" }

Three requirements, each of which the API enforces:

FieldRuleError if wrong
call_idRequired. Not idUnknown parameter 'id' / Missing call_id in content of type function_result
nameRequired. The tool's name, repeatedMissing name in content of type function_result
resultMust be an object, a FunctionResultSubcontent[], or a string'result' must be a Struct, FunctionResultSubcontent[], or string

That last one catches people out. A bare number or boolean is rejected, so 42 fails and "42" succeeds. Freyja sends a JSON object through unchanged and sends anything else as a string.

Ordering is enforced​

Please ensure that function call turn comes immediately after a user turn
or after a function response turn.

A function_call step cannot open a conversation or follow arbitrary steps.

Thought signatures must be replayed​

This is the most important thing on this page.

A response to a tool-calling prompt contains a thought step carrying an opaque signature:

"steps": [
{ "type": "thought", "signature": "EvACCu0CARFNMg+gcIqp9LOeN37O777Mv012FS4SXRUGoRN1n6+4CMDZ0Rr..." },
{ "type": "function_call", "id": "mbbykw8q", "name": "add", "arguments": { "b": 22, "a": 20 } }
]

When you send the tool result back, that thought step must be included, verbatim, in the same position. Measured behavior:

InputResult
Model's steps echoed back unchangedcompleted, correct answer
thought step droppedRequest contains an invalid argument
function_call rebuilt by hand, no signatureRequest contains an invalid argument

A semantically identical call is not good enough. The signature is what the API validates, and it cannot be reconstructed.

Freyja handles this with OutputContent::Reasoning { data }, which preserves any step it does not model, and GenerateResponse::to_message(), which carries it into the next request. As long as you append response.to_message() before your tool results, it works. See Tool calling.

Response body​

{
"id": "v1_ChczQWgyYXVuck9adnZnOFVQOWFydG1Bdx...",
"object": "interaction",
"model": "gemini-3.5-flash",
"status": "requires_action",
"created": "2026-08-07T16:33:32Z",
"updated": "2026-08-07T16:33:32Z",
"service_tier": "standard",
"steps": [
{ "type": "thought", "signature": "..." },
{ "type": "function_call", "id": "mbbykw8q", "name": "add", "arguments": { "b": 22, "a": 20 } }
],
"usage": {
"total_tokens": 190,
"total_input_tokens": 67,
"total_output_tokens": 18,
"total_cached_tokens": 0,
"total_tool_use_tokens": 0,
"total_thought_tokens": 105,
"raw_prompt_token": 107,
"input_tokens_by_modality": [ { "modality": "text", "tokens": 67 } ]
}
}

Output arrives in steps, not output or candidates. Text lives inside a model_output step's content array.

Status values​

ValueNeutral ResponseStatus
completedCompleted
incompleteIncomplete
budget_exceededIncomplete
requires_actionRequiresAction
failedFailed
cancelledFailed
anything elseOther(String)

Usage​

Gemini reports more detail than the neutral Usage models. Freyja maps total_input_tokens, total_output_tokens, total_tokens, and total_cached_tokens, which becomes Usage::cached_input_tokens. Gemini caches a repeated prefix on its own.

The rest is discarded, not preserved. total_thought_tokens, total_tool_use_tokens, raw_prompt_token, and input_tokens_by_modality are all dropped. provider_metadata is built by flattening the response body's unknown top-level keys; usage is a named field deserialized into a struct holding exactly the three mapped counts, with no catch-all, so its other subfields do not survive deserialization. Top-level fields such as object, created, updated, and service_tier do reach provider_metadata. Usage detail does not, read the raw body for it.

Note that thinking tokens are billed. The 190 total above includes 105 thought tokens for a one-line arithmetic question, and total_tokens is the only place that cost is visible through Freyja.

Streaming​

Client::stream() sends the same body with "stream": true added, to the same URL with ?alt=sse appended. Both are needed: the body field asks for incremental generation, the query parameter is what makes the response SSE-framed.

Then the part most likely to trip you up, and the mirror image of Anthropic:

The event name is inside the JSON body, as event_type, not on the SSE event: line. Freyja reads event_type and ignores the event: line entirely. If you are tailing frames by hand and matching on event:, you will see nothing useful.

data: {"event_type":"step.delta","index":0,"delta":{"type":"text","text":"The answer"}}
event_typeWhat the decoder does with it
step.startOpens a step at index. function_call starts a call with its id and name, thought starts a signature reconstruction, model_output is noted so its end can be marked, any other step type is held whole to be replayed
step.deltaDispatches on delta.type, see below
step.stopCloses the step at index. This is what keeps two adjacent model_output steps as two text parts rather than one
interaction.completed, interaction.failed, interaction.incompleteTerminal. Carries the whole interaction object: id, model, status, and usage

The delta subtypes:

delta.typeCarries
textdelta.text, a fragment of generated text
arguments_deltadelta.arguments, a fragment of the tool call's arguments
thought_summarydelta.content.text, human-readable reasoning. Note the extra nesting
thought_signaturedelta.signature, appended into the thought step being reconstructed

Anything else is merged field by field into the unmodeled step at that index, string fields appending and everything else replacing, so a step type Freyja does not model still replays with whatever its deltas carried. A code_execution step would otherwise lose its code.

Both arguments_delta and thought_signature are correlated by the frame's index, which counts steps.

The thought step is reconstructed rather than echoed whole: the signature streams in as fragments and Freyja merges them back into the step the API sent at step.stop. Since replaying thought signatures verbatim is what makes multi-turn tool calling work here, use into_response().to_message() to build the next turn rather than assembling one from StreamEvent::ReasoningDelta, which is the human-readable summary and carries no signature.

Any event_type not listed above is ignored, including an error frame. This dialect has no error arm by design: a failure surfaces as the HTTP status before the stream begins, or as the terminal interaction.failed status, which maps to ResponseStatus::Failed exactly as the non-streaming parser does for the same body.

usage on the terminal frame is read leniently, defaulting to zero, matching the non-streaming parser.

See Streaming.

Errors​

{ "error": { "message": "Unknown parameter 'id' at 'input[2].content[0]'.", "code": "invalid_request" } }

The messages are precise and include a JSON path, which makes them the fastest way to debug a mapping problem. Freyja preserves the whole body alongside the classified status, so nothing is lost.

The exception is Request contains an invalid argument, a generic protobuf-level rejection with no path. In practice that one usually means a missing or malformed thought signature.

What Freyja does not send​

Nothing, on this dialect. Every neutral field has somewhere to go here, so nothing is refused before the request is built, metadata and three reasoning_effort levels reach the endpoint and are declined there. See Gemini.