Skip to main content
google avatar

Gemini 3.7 Flash API

google/gemini-3.7-flash

Reasoning-first flagship text model for coding and agentic work, with tunable thinking levels, tool calling and streaming over an OpenAI-compatible endpoint.

Context window
1M tokens
Max output
65.5K tokens
Input
$0.75 / 1M tokens
Output
$3.75 / 1M tokens
Cached input
$0.075 / 1M tokens
Modalities
text → text
Features
reasoningtool callingjson modestreaming

Connect to Gemini 3.7 Flash

Gemini 3.7 Flash is served through an OpenAI-compatible chat completions API. Point any OpenAI SDK or OpenAI-compatible tool at the base URL below with a ModelRunner API key — no polling, the reply comes back in the response (or streams).

base_url
https://queue.modelrunner.run/google/gemini-3.7-flash
model
google/gemini-3.7-flash
auth
Authorization: Bearer <MODELRUNNER_API_KEY>get a key
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://queue.modelrunner.run/google/gemini-3.7-flash",
    api_key=os.environ["MODELRUNNER_API_KEY"],
)

completion = client.chat.completions.create(
    model="google/gemini-3.7-flash",
    messages=[
      {
        "role": "user",
        "content": "Explain what an API rate limit is in two sentences."
      }
    ],
    reasoning_effort="medium",  # low | medium | high — thinking bills as output tokens
)
print(completion.choices[0].message.content)

# Streaming: add stream=True and iterate the chunks
# for chunk in client.chat.completions.create(..., stream=True):
#     print(chunk.choices[0].delta.content or "", end="")
Works withCline · Continue · Claude Code · LangChain · Vercel AI SDK · LiteLLM · Aider

Cline → Settings → API Configuration (or the CLI line below)

API Provider:  OpenAI Compatible
Base URL:      https://queue.modelrunner.run/google/gemini-3.7-flash
API Key:       <your ModelRunner API key>
Model ID:      google/gemini-3.7-flash

# Cline CLI equivalent
cline auth --provider openai --baseurl https://queue.modelrunner.run/google/gemini-3.7-flash --modelid google/gemini-3.7-flash --apikey <your ModelRunner API key>

Streaming via SSE (stream: true; ends with data: [DONE]) · Non-streaming calls time out at ~290 s — stream long generations · 10 MB request body · Errors use the OpenAI error envelope · Optional metadata object for your own tags, never sent to the model · Many models, one provider entry: base_url https://queue.modelrunner.run/v1 (GET /v1/models lists ids; model field required)

From an MCP client (Claude Desktop, Cursor, Claude Code): connect the ModelRunner MCP server once and its run_model tool runs Gemini 3.7 Flash with a messages input — the reply comes back in the same call.

Machine-readable: OpenAPI schema · llms.txt

Example conversation

A real run of Gemini 3.7 Flash on ModelRunner · charged $0.0246 · 58 in / 960 out / 1,370 reasoning tokens

A function is supposed to return the k-th largest element of an unsorted list. This implementation is subtly wrong: def kth(nums, k): return sorted(nums)[k]. Find every bug, explain why each is wrong, and give a corrected version with its time complexity.

Here is a complete breakdown of the bugs in the implementation, why they occur, and the corrected implementations.

---

### 1. The Bugs Explained

#### **Bug 1: Ascending order vs. Largest element (Direction Error)** * **Why it's wrong:** `sorted(nums)` sorts elements in **ascending order** (from smallest to largest). Accessing positive indices from the front (`[k]`) retrieves elements starting from the *smallest*, not the *largest*. * **Example:** For `nums = [3, 2, 1, 5, 6, 4]`, `sorted(nums)` is `[1, 2, 3, 4, 5, 6]`. Accessing from the front looks at `1, 2, 3...` rather than `6, 5, 4...`.

#### **Bug 2: 1-indexed vs. 0-indexed (Off-by-One Error)** * **Why it's wrong:** In computer science conventions and standard problem descriptions (e.g., LeetCode 215), the "$k$-th largest" element is **1-indexed**: * $k = 1$ means the *1st largest* (maximum element). * $k = 2$ means the *2nd largest*, and so on. * If a caller passes $k=1$, the original function accesses index `1` of the sorted list, which is actually the **2nd smallest element** (due to 0-based indexing in Python).

#### **Bug 3: Index Out of Bounds on $k = \text{len}(nums)$** * **Why it's wrong:** If a user wants the $n$-th largest element (where $n = \text{len}(nums)$, i.e., the minimum element), passing $k = n$ will execute `sorted(nums)[n]`, which raises an `IndexError` because valid indices are $0$ to $n-1$.

---

### 2. Corrected Versions

#### **Option A: Direct Fix (Simple Sorting)** Using Python's negative indexing (where `[-1]` is the largest, `[-2]` is the 2nd largest, and `[-k]` is the $k$-th largest):

```python def kth_largest(nums: list[int], k: int) -> int: if not 1 <= k <= len(nums): raise ValueError( f"k must be between 1 and {len(nums)}, but got {k}" ) return sorted(nums)[-k] ``` *(Alternatively: `return sorted(nums, reverse=True)[k - 1]`)*

* **Time Complexity:** **$O(N \log N)$** — where $N$ is the number of elements in `nums` (due to Timsort). * **Space Complexity:** **$O(N)$** — `sorted()` creates a new sorted list of size $N$.

---

#### **Option B: Optimal for Small $k$ / Standard Library (`heapq`)** If $k \ll N$, sorting the entire list is inefficient. Using a min-heap or Python’s built-in `heapq.nlargest`:

```python import heapq

def kth_largest(nums: list[int], k: int) -> int: if not 1 <= k <= len(nums): raise ValueError( f"k must be between 1 and {len(nums)}, but got {k}" ) return heapq.nlargest(k, nums)[-1] ```

* **Time Complexity:** **$O(N \log k)$** — maintaining a heap of size $k$ across $N$ elements. * **Space Complexity:** **$O(k)$** — to store the heap.

---

#### **Option C: Optimal Average Time (Quickselect)** For optimal theoretical performance, the Quickselect algorithm finds the $k$-th largest element without sorting the entire array:

* **Average Time Complexity:** **$O(N)$** * **Worst-case Time Complexity:** **$O(N^2)$** (can be mitigated with randomized pivots). * **Space Complexity:** **$O(1)$** auxiliary space (iterative) or $O(\log N)$ (recursive call stack).

Model Pricing

Pricing

This model is billed per token, at separate rates for what you send and what it produces.

Input tokens
$0.75
per 1M tokens
Cached input tokens
$0.075
per 1M tokens
Output tokens
$3.75
per 1M tokens

If a run reports no token usage, it bills a flat $0.01.

Cost estimator

Estimate from the rates above — your bill is the model's reported usage × rate, exact to 6 decimals.

Per request$0.00337
Per day$3.381,000 requests

This model thinks before it answers. Thinking tokens bill at the output rate and are often several times the visible reply — count them in the output figure, or set a lower reasoning effort.

Compare tiers and related models

ModelInput / 1MOutput / 1MContextMax outputFeatures
Gemini 3.7 Flashgoogle/gemini-3.7-flash$0.75$3.751M65.5Kreasoning, tool calling, json mode
Gemini 3.5 Flashgoogle/gemini-3.5-flash$1.5$91M65.5Kreasoning, tool calling, json mode
Gemini 3.5 Flash-Litegoogle/gemini-3.5-flash-lite$0.3$2.51M65.5Ktool calling, json mode
DeepSeek V4 Prodeepseek/v4$2.4$4.81M393.2Kreasoning, tool calling, json mode
GLM-5.2z-ai/glm-5.2$1.4$4.41M131.1Kreasoning, tool calling, json mode
GLM-5.2 Fast Previewz-ai/glm-5.2-fast-preview$2.8$8.81M131.1Kreasoning, tool calling, json mode
Qwen3.8-Maxalibaba/qwen3.8-max$2$61M131.1Kreasoning, tool calling, json mode

Request parameters

The body follows OpenAI’s chat completions shape. Fields below are the ones this model documents; anything else the platform does not interpret is forwarded to the model unchanged, and the model is the authority on what it accepts.

Request parameters of Gemini 3.7 Flash
NameTypeRequiredDescription
messagesarrayyesOpenAI-style conversation history. Each item is an object with a role (system, user, assistant or tool) and content.
streambooleannoReturn the reply as a Server-Sent Events stream of deltas terminated by data: [DONE]. Default: false.
reasoning_effortenumnoHow much the model thinks before answering. Thinking tokens bill as output tokens. One of: low, medium, high. Default: "medium".
max_tokensintegernoUpper bound on generated tokens. Thinking consumes this budget, so allow generous headroom.
toolsarraynoOpenAI-format tool definitions the model may call.
tool_choicenoauto, none, required, or a specific tool.
response_formatobjectnoSet {"type":"json_object"} for JSON mode.
stopnoUp to 4 stop sequences.
seedintegernoBest-effort determinism hint.

Response

An OpenAI ChatCompletion object: id, object, created, model, choices[] and usage (whose completion_tokens_details.reasoning_tokens reports thinking). The id is chatcmpl-<requestId>, and the same request appears in your dashboard.

About Gemini 3.7 Flash

Gemini 3.7 Flash is a **thinking model**: it reasons internally before answering, which makes it markedly stronger on complex coding, multi-step agentic workflows and reliable tool use than a single-pass model of similar cost.

Best for

  • Agentic coding loops that need reliable multi-step tool use
  • Hard reasoning tasks where a thinking model beats a single-pass one
  • Drop-in OpenAI-compatible endpoint for a coding assistant
  • Trade cost against answer quality by tuning the thinking level

How it thinks

Gemini 3.7 Flash reasons before it answers. Set reasoning_effort to low, medium or high (default medium) to trade answer quality against latency and cost. Thinking tokens are billed at the output rate and reported as usage.completion_tokens_details.reasoning_tokens.

Notesshow the full description ›

Thinking is on by default at a `medium` level and is tunable (`low`, `medium`, `high`) — more thinking generally means better answers on hard problems and higher cost, since thinking tokens are billed as output tokens and draw from the same `max_tokens` budget as the visible reply, so leave generous headroom.

⚠️ This generation **no longer accepts the `temperature`, `top_p` and `top_k` sampling parameters**. Tools that send them by default may need them disabled.

## Choose another model when - The task is everyday summarisation, extraction or rewriting where a single pass is enough — Gemini 3.5 Flash does that at a lower output rate - Volume matters more than depth — Gemini 3.5 Flash-Lite is the cheap tier - Your input includes images, audio or video — this endpoint is text-only

## Tips - Drop `reasoning_effort` to `low` when speed matters more than depth; raise it to `high` for non-trivial coding or multi-step tool loops - `usage.completion_tokens_details.reasoning_tokens` in the response reports how much of the reply went to thinking

Behaviour & limits

Context window
1M tokens (input + output)
Max output
65.5K tokens per reply — thinking counts against this budget
Structured calls
OpenAI-format tools + tool_choice · response_format JSON mode
Transport
OpenAI-compatible chat completions · SSE streaming · ~290 s non-stream ceiling · 10 MB body

FAQ

How do I connect to Gemini 3.7 Flash through the API?

Gemini 3.7 Flash is served by an OpenAI-compatible chat completions endpoint. Point any OpenAI SDK or OpenAI-compatible tool at base_url https://queue.modelrunner.run/google/gemini-3.7-flash with a ModelRunner API key (Authorization: Bearer <key>) and model google/gemini-3.7-flash; the SDK appends /chat/completions itself. The call is synchronous — the reply comes back in the response body, or streams as Server-Sent Events with "stream": true. Do not submit it to the asynchronous queue path, which returns HTTP 400 for this model.

How much does Gemini 3.7 Flash cost?

Gemini 3.7 Flash is billed per token from the usage the model reports: $0.75 per 1M input tokens, $0.07 per 1M cached input tokens, $3.75 per 1M output tokens. Thinking (reasoning) tokens bill at the output rate. There is no per-request minimum — a short call bills a fraction of a cent, exact to six decimals.

What is Gemini 3.7 Flash's context window?

Gemini 3.7 Flash supports a 1M-token context window and up to 65.5K output tokens per reply — thinking tokens count against the output budget, so leave headroom in max_tokens.

Can I use Gemini 3.7 Flash in GitHub Copilot or another tool that requires a /models endpoint?

Yes. Custom-provider flows that probe GET {base_url}/models before first use (GitHub Copilot's BYOK flow does) work with either base URL: https://queue.modelrunner.run/google/gemini-3.7-flash self-describes at https://queue.modelrunner.run/google/gemini-3.7-flash/models, and the platform base https://queue.modelrunner.run/v1 covers every public chat model with one provider entry — GET /v1/models lists the ids and the request's model field selects google/gemini-3.7-flash.

Does Gemini 3.7 Flash support streaming?

Yes. Set "stream": true and the reply arrives as Server-Sent Events (data: frames ending with data: [DONE]); stream_options: {"include_usage": true} adds a final usage frame. Non-streaming calls are cut off at about 290 seconds, so stream long generations.

Does Gemini 3.7 Flash support tool calling or JSON mode?

Gemini 3.7 Flash supports function calling via an OpenAI-format tools array with tool_choice and JSON mode via response_format {"type": "json_object"}. Both are passed through to the model in the standard OpenAI chat completions shape, so existing client code works unchanged.

What happens if my ModelRunner balance runs out while calling Gemini 3.7 Flash?

The request is refused with HTTP 429 and an OpenAI-style error whose code is insufficient_quota — the convention OpenAI SDKs already understand — and nothing is charged. Top up in the dashboard and retry. (Disconnecting from a stream after output has started is not a refund — the platform finishes the upstream call and bills its exact usage.)