Gemini chat
Call Gemini models through OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages.
| Purpose | Endpoint |
|---|---|
| Base URL | https://api.hop-base.com/v1 (Anthropic Messages uses https://api.hop-base.com) |
| Chat (OpenAI Chat Completions) | POST /v1/chat/completions |
| Chat (OpenAI Responses) | POST /v1/responses |
| Chat (Anthropic Messages) | POST /v1/messages |
The two Gemini plan groups support different parameters. Read "Group differences" below before you integrate.
Your first request
Gemini chat models can be called through three protocols: OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages. The example below uses Chat Completions. Authenticate with Authorization: Bearer sk-your-key; x-api-key also works.
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.8-flash",
"messages": [{"role": "user", "content": "Hello"}]
}'Available Gemini models vary by plan group. Call GET /v1/models with the current key and only use complete IDs returned by that response.
x-goog-api-key and /v1beta/models/{model}:generateContent are not supported. Both Gemini groups serve /v1/chat/completions, /v1/responses, and /v1/messages; Gemini Official Direct also provides /v1/messages/count_tokens (a local estimate, not billed). The details of each protocol differ between the groups; see "Group differences" below.
Available models
| Family | Model ID | Use case |
|---|---|---|
| Gemini 4 | gemini-4-argon | Gemini 4 generation · 1M context |
| Gemini 3.8 | gemini-3.8-flash | Latest Flash · default |
| Gemini 3.7 / 3.6 | gemini-3.7-flash / gemini-3.6-flash | Previous Flash |
| Gemini 3.5 | gemini-3.5-flash / gemini-3.5-flash-lite | Stable Flash / low cost |
| Gemini 3.1 Pro | gemini-3.1-pro-previewgemini-3.1-pro-preview-customtools | Advanced reasoning preview / tool-use preview |
| Gemini 3.1 | gemini-3.1-flash-lite / gemini-3.1-flash-lite-preview | Lightweight / lightweight preview |
| Gemini 3 | gemini-3-flash-preview | Gemini 3 Flash preview |
| Gemini 2.5 | gemini-2.5-progemini-2.5-flashgemini-2.5-flash-lite | Stable models |
Use gemini-3.8-flash by default. Treat every model ID containing preview as a preview without a stability guarantee.
Rates vary by plan group. The signed-in model catalog for the current key is authoritative.
Group differences
| Capability | Gemini Official Direct | Gemini (all models, incl. image) |
|---|---|---|
| Endpoints | /v1/chat/completions, /v1/responses, /v1/messages (Claude Code connects directly through CC Switch; the model name must be a Gemini model ID) | /v1/chat/completions, /v1/responses, and /v1/messages (Claude Code connects directly; Codex CLI is not supported) |
| Request body format | Each protocol's standard format; /v1/chat/completions also accepts Gemini-native contents | OpenAI messages only |
| Tool calling | tools and tool_choice on all three protocols, including parallel calls and multi-turn; Responses also supports custom free-form tools | Supported; returns tool_calls |
| Structured output | Supported: response_format on Chat, text.format on Responses, output_format / output_config.format on Messages | Supports response_format |
stop / n | stop works; n accepts 1–8 and returns that many choices | stop works; n returns only 1 choice |
| Image input | base64 only (data URLs on Chat, base64 sources on Messages) | Data URLs and public https URLs |
| Streaming | All three protocols; output may arrive in chunks only after the full response is generated | Streams token by token |
| Per-request time limit | About 100 seconds, then retried on another account | No fixed limit |
| Available models | The full list above | Fewer; GET /v1/models is authoritative |
Gemini (all models, incl. image) supports structured output through response_format with json_object and json_schema.
Gemini Official Direct: Chat Completions parameters
messages: supported content parts aretext,image_url,input_audio,file,refusal; any other type returns 400.image_urlaccepts only base64 data URLs. Forfile,file_datamust be a data URL, andfile_idis not supported.role: "tool"results are sent to the model as function results.tools/tool_choice:tool_choiceacceptsauto,none,required, a named function, andallowed_tools. Parallel tool calls and multi-turn tool use are supported. Withparallel_tool_calls: false, only the first call is kept. The legacyfunctions/function_callfields also work. Tool parameter schemas are accepted as full JSON Schema, so$ref,$defs,anyOf,additionalProperties, and similar keywords need no rewriting.response_format:json_objectandjson_schema.stop: a string or an array.n: 1–8, returning that manychoices.max_tokens/max_completion_tokens: if both are sent,max_tokenswins; thinking tokens count against it, so use at least 4096.temperature/top_p: forwarded unchanged within the model's official range.seedandtop_kare also supported.presence_penalty/frequency_penalty: ignored when 0. Non-zero values are forwarded unchanged, and current Gemini models return 400Penalty is not enabled for this model.reasoning_effort: mapped to a thinking budget; see "Thinking" below.- Fields that return 400:
logprobs,top_logprobs,logit_bias,modalities,audio,web_search_options(modalitiesonly when it includes a value other thantext). - Fields that are ignored and do not affect output:
user,metadata,store,service_tier,safety_identifier,prompt_cache_key,stream_options,prediction,verbosity.
For general field descriptions, see the Chat Completions API reference.
Gemini Official Direct: Responses and Anthropic Messages
Responses (POST /v1/responses)
- Tools:
functiontools andcustomfree-form tools (such as Codex'sapply_patch) are supported. Built-in or hosted tools (web_search,file_search,code_interpreter,computer, and so on) return 400.tool_choicetakes the same values as on Chat Completions, andmax_tool_callstruncates the number of calls. - Stateless:
previous_response_id,conversation,background,prompttemplates, anditem_referencereturn 400. Send the full history ininputon every request (Codex does this by default). - Structured output uses
text.format. - Fields that are ignored and do not affect output:
store,include,user,metadata,safety_identifier,prompt_cache_key,service_tier,truncation,text.verbosity.
Anthropic Messages (POST /v1/messages)
- Set the Base URL to
https://api.hop-base.com(no/v1). Claude Code connects directly through CC Switch. The model name must be a Gemini model ID such asgemini-3.8-flash;claude-*names are not mapped automatically. tool_choiceacceptsauto,any,tool, andnone. Withdisable_parallel_tool_use: true, only the first call is kept.image/documentblocks accept only base64 sources;urlsources return 400.tool_resultcan carry images.- Structured output uses
output_formatoroutput_config.format(json_schema). /v1/messages/count_tokensis a local estimate and is not billed.- Fields that are ignored and do not affect output:
metadata,service_tier,cache_control,context_management.
Thought signatures (multi-turn tool use)
Tool calls from Gemini 3 and later models carry a thought signature. Where it appears in each protocol:
| Protocol | Location |
|---|---|
| Chat Completions | tool_calls[].extra_content.google.thought_signature |
| Responses | encrypted_content on the reasoning output item |
| Anthropic Messages | redacted_thinking block |
Send the assistant message back unchanged on the next turn. If your client drops these fields, the request still succeeds: the gateway tries to recover the signature, and if it cannot, it skips validation the way the official API allows. Reasoning continuity may be slightly lower in that case.
- A public image link returns 400
image_url only supports data URLs (base64-embedded images). - Unsupported content part types (such as
video_url) return 400 instead of being dropped silently. messageswith no usable content returns 400.
Streaming with SSE (add "stream": true)
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{"model": "gemini-3.1-pro-preview", "stream": true,
"messages": [{"role": "user", "content": "Hello"}]}'On the Gemini Official Direct group, all three protocols support "stream": true, and the events follow the OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages specifications respectively, including tool-call deltas. The stream may be sent in chunks only after the full response is generated, so the first chunk can arrive around the time the full response is ready; this applies to all three protocols. On Chat Completions, the last chunk always carries usage.
The Gemini (all models, incl. image) group streams token by token. Add stream_options.include_usage when you need usage.
A non-streaming response carries the charge in usage: cost_usd is the USD amount actually deducted from your balance, cost is the same charge in CNY, and currency is the currency of cost (always CNY), with the same values in the X-HopBase-Cost / X-HopBase-Cost-USD / X-HopBase-Currency response headers. Streaming responses carry none of these; check the charge under Usage in the console. See Charges.
Thinking
Gemini models think by default, and thinking cannot be fully turned off. Thinking tokens count against your output limit. If max_tokens is too low, you can get finish_reason=length with only a few characters of text, so use at least 4096.
In the OpenAI format, thinking tokens are included in completion_tokens and also reported in completion_tokens_details.reasoning_tokens (on Gemini Official Direct's Responses endpoint, in output_tokens_details.reasoning_tokens). In the native format they appear in usageMetadata.thoughtsTokenCount.
The Gemini Official Direct group maps reasoning_effort to a thinking budget:
reasoning_effort | Thinking budget |
|---|---|
none / minimal | 0 |
medium | 8192 |
high | 24576 |
low and other values | Model default |
gemini-4-argon accepts only thinking levels and does not use the budgets above: none / minimal → low, medium → medium, high → high; low behaves like omitting the field and uses the model's default level. Its thinking cannot be turned off.
On Responses, enabling reasoning.summary returns a reasoning summary. On Anthropic Messages, thinking.type set to enabled or adaptive returns thinking blocks, and budget_tokens above 24576 is capped at 24576.
Billing on Gemini Official Direct: thinking tokens are billed as output, and tokens that built-in tools feed back to the model (toolUsePromptTokenCount) are billed as input. usage follows each protocol's standard shape; on Anthropic Messages, input_tokens excludes cache reads, which are reported in cache_read_input_tokens.
On the Gemini (all models, incl. image) group, none noticeably reduces thinking.
Gemini-native payload passthrough
Request bodies carried over from the Gemini SDK can be sent as-is. On the Gemini Official Direct group, the same endpoint also accepts the native contents field and returns the native response shape.
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.8-flash",
"contents": [{"role": "user", "parts": [{"text": "Hello"}]}]
}'The native format accepts only the official top-level fields:
contents, systemInstruction, generationConfig, safetySettings, tools,
toolConfig, cachedContent, labels, serviceTier, modelAny other field, such as store, max_tokens, or messages, returns 400 Unknown name …. The native format does not support streaming, so do not send "stream": true.
Next steps
- For Gemini image generation (Banana), see the Image API
- When something fails, check Troubleshooting