# 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. ## Overview - **Endpoint**: `https://queue.modelrunner.run/google/gemini-3.7-flash` - **Model ID**: `google/gemini-3.7-flash` - **Category**: text-to-text - **Kind**: inference - **Tags**: gemini, gemini-3.7, flash, llm, text-to-text, chat, chat-completions, openai-compatible, reasoning, thinking, agentic, coding, streaming, tool-calling, json-mode ## Pricing - **Input tokens**: $2.1 per 1M - **Cached input tokens**: $0.21 per 1M - **Output tokens**: $10.5 per 1M ## Request Lifecycle This model runs on the ModelRunner **asynchronous queue API** — a single POST does not return the output. Every call requires an `Authorization: Key $MODEL_RUNNER_KEY` header. Run three steps: 1. **Submit** — `POST https://queue.modelrunner.run/google/gemini-3.7-flash` with a JSON body holding the input fields at the top level. The body may also include a reserved top-level `metadata` object — a flat string map (max 16 keys, key ≤64 / value ≤512 chars) stored on the request for your own tagging. It is never sent to the model; filter your request history with `GET https://queue.modelrunner.run/requests?metadata=` (exact key=value matches, AND-ed). The response carries request handles only (no output yet): ```json { "status": "IN_QUEUE", "request_id": "<21-char id>", "status_url": "https://queue.modelrunner.run/google/gemini-3.7-flash/requests//status", "response_url": "https://queue.modelrunner.run/google/gemini-3.7-flash/requests/", "cancel_url": "https://queue.modelrunner.run/google/gemini-3.7-flash/requests//cancel" } ``` 2. **Poll status** — `GET ` until `status` is `COMPLETED`. Possible values are `IN_QUEUE`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED`. A `FAILED` request responds with HTTP 400 and an `error` field. 3. **Read result** — `GET `. Returns the finished request, including the generated `output`: ```json { "id": "", "status": "COMPLETED", "output": ..., "input": ... } ``` The JavaScript and Python SDKs below perform steps 2–3 for you. In any language without an SDK (Swift, Go, Kotlin, etc.) you must implement the polling loop and the final result fetch yourself — see the cURL example for the full flow. ### Input Schema - **`seed`** (`integer`, _optional_): Best-effort determinism hint. - **`stop`** (`unknown`, _optional_): Up to 4 stop sequences. - **`tools`** (`array`, _optional_): OpenAI-format tool definitions the model may call. - **`stream`** (`boolean`, _optional_): Return the reply as a Server-Sent Events stream of deltas terminated by \`data: \[DONE\]\`. - Default: `false` - **`messages`** (`array`, _required_): OpenAI-style conversation history. Each item is an object with a \`role\` (\`system\`, \`user\`, \`assistant\` or \`tool\`) and \`content\`. - **`max_tokens`** (`integer`, _optional_): Upper bound on generated tokens. Thinking consumes this budget, so allow generous headroom. - Range: `1` to `"+inf"` - **`tool_choice`** (`unknown`, _optional_): \`auto\`, \`none\`, \`required\`, or a specific tool. - **`response_format`** (`object`, _optional_): Set \`{"type":"json_object"}\` for JSON mode. - **`reasoning_effort`** (`string`, _optional_): How much the model thinks before answering. Thinking tokens bill as output tokens. - Default: `"medium"` - Options: `"low"`, `"medium"`, `"high"` ### Output Schema - **`id`** (`string`, _optional_): - **`model`** (`string`, _optional_): - **`usage`** (`object`, _optional_): - **`object`** (`string`, _optional_): - **`choices`** (`array`, _optional_): - **`created`** (`integer`, _optional_): ## Default Example **Input** ```json { "messages": [ { "role": "user", "content": "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." } ], "max_tokens": 8000, "reasoning_effort": "high" } ``` **Output** ```json { "id": "chatcmpl-09TWMsiJF9xVoSoeRqdWw", "model": "google/gemini-3.7-flash", "usage": { "total_tokens": 2081, "prompt_tokens": 58, "completion_tokens": 663, "completion_tokens_details": { "reasoning_tokens": 1360 } }, "object": "chat.completion", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Here is the breakdown of the bugs in the implementation, why they occur, and the corrected solutions.\n\n---\n\n### **Bugs Identified**\n\n1. **Sort Direction (Ascending instead of Descending):**\n * **Why it's wrong:** `sorted(nums)` sorts the list in **ascending** order (smallest to largest). Accessing an index from the beginning gives the smallest elements, not the largest.\n\n2. **1-based vs. 0-based Indexing (Off-by-One Error):**\n * **Why it's wrong:** Natural language definitions of \"$k$-th largest\" use 1-based indexing (e.g., $k=1$ is the 1st largest / maximum). \n * In Python, lists are 0-indexed. Passing $k=1$ to `sorted(nums)[1]` returns the *2nd smallest* element rather than the *1st largest*.\n\n3. **Index Out of Bounds on Boundary Value ($k = \\text{len}(nums)$):**\n * **Why it's wrong:** If a caller asks for the $N$-th largest element of a list with length $N$ (i.e., the absolute smallest element), accessing index `[N]` will raise an `IndexError` because valid indices are `0` through `N - 1`.\n\n---\n\n### **Corrected Implementations**\n\n#### **1. Direct Fix (Sorting Approach)**\nUsing negative indexing (`-k`), which directly accesses the $k$-th element from the end of an ascending list:\n\n```python\ndef kth_largest(nums: list[int], k: int) -> int:\n if not 1 <= k <= len(nums):\n raise IndexError(\"k must be between 1 and len(nums)\")\n return sorted(nums)[-k]\n```\n*(Alternatively: `return sorted(nums, reverse=True)[k - 1]`)*\n\n* **Time Complexity:** $\\mathcal{O}(N \\log N)$, where $N$ is the number of elements in `nums` (due to Timsort).\n* **Space Complexity:** $\\mathcal{O}(N)$ to store the sorted array.\n\n---\n\n#### **2. Optimal Standard Library Fix (Min-Heap / `heapq`)**\nIf efficiency is important, finding the $k$-th largest element does not require sorting the entire list:\n\n```python\nimport heapq\n\n\ndef kth_largest(nums: list[int], k: int) -> int:\n if not 1 <= k <= len(nums):\n raise IndexError(\"k must be between 1 and len(nums)\")\n return heapq.nlargest(k, nums)[-1]\n```\n\n* **Time Complexity:** $\\mathcal{O}(N \\log k)$, which is much faster than sorting when $k \\ll N$.\n* **Space Complexity:** $\\mathcal{O}(k)$ to maintain the heap.\n\n*(Note: For $\\mathcal{O}(N)$ average time complexity, the **Quickselect** algorithm can also be used).*", "extra_content": { "upstream": { "thought_signature": "AY89a1+V7zqkhnPwiPyEYEc8cdi1F7e5gctyEUq3AyhHfVOmESv4aaCo9Fsm8WjaV5vrbNBxhpmE4U3TRjuJ+184O5Eu/8AUiyvTB45dmvKY7mJc5l7xUhiTyOt12FEpiLIzd1OKgn0h0BzYE+QdncKY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TCZ1rOLPblTI08NygGrhzNFzTfhzAevsw221c5g3HWayanK8+lZdoqWDvM4vF0oZywtmiL/l/SQJFQIUwp7Uc0bJoFivvHoXv9irSvg1iM3CY9RZ9o/DBE5Y5rIAO9WR2iWgyxZHdJJY6/sSjIAzb0Fl8yaj7YAACsCw/7tHfiHBA/9vsztM5/M+czrT8LYUSeCKXUhjXKY0WyHNpe+CshxMBnZREpM2X5sFYOIhcj/d7ze0ELhyZKBWoRKXj0D/JcDwCPqvd5vW88e4DrQXcELcACvaBf/3K4mJObvrg5Di676BFt4T88M3JFDHFgeBwc3ANwZL/PuwwDvSBJUnZ50YIpAlKdIdegHSVERur3QWCfhpk+treWqnT9DfHNlz1uwKS3PfSUJRl5B0AdkNX4W16XzViuUwMmxSUwBtZpRvhYNeRpgntMkq0VFpr797lsLQe3gYEgj+WqamvBqSphA8012KKzR5AD46w/bx/k947W5GmfAn6gROolB3MD7vEZl5pAZqSnhmZYfRJAW96gTuNgK6qSTQ9B2Lq5jooGzwtiB7c55+ByZ4KGTKHv/278YFlHZGH07Axw6ZYMxSZAtpDMLAjrXf+UqnuqAhO1mHx5ysjorD8ffBRi5gSM8J2i/+m+Wu52Nl5NUKThrGt2KCwwSl5q+SLHACqUEGkwXfHiVEe8P/1AX0ncOYM0H6vo8UUASxtScwIPiNBDsBUuX1sYZwAZ0SFAY6lzjjxBwuBfsm1MwayQj5OB00FPRKv9Bn0rN6GlbWlEjEWz6c9BZHYxmcqiXj6H/V7me5rh54Ks/7vU1NAr0qejXwgCnPy9Fjpn6IrpZUuKA==" } } }, "logprobs": null, "finish_reason": "stop" } ], "created": 1786739870 } ``` ## Usage Examples ### cURL The queue API is asynchronous: submit the request, poll `status_url` until it is `COMPLETED`, then read the result from `response_url`. Requires `jq`. ```bash # 1. Submit the request (returns request handles, not the output) SUBMIT=$(curl --silent --request POST \ --url https://queue.modelrunner.run/google/gemini-3.7-flash \ --header "Authorization: Key $MODEL_RUNNER_KEY" \ --header "Content-Type: application/json" \ --data '{ "messages": [ { "role": "user", "content": "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." } ], "max_tokens": 8000, "reasoning_effort": "high" }') STATUS_URL=$(echo "$SUBMIT" | jq -r '.status_url') RESPONSE_URL=$(echo "$SUBMIT" | jq -r '.response_url') # 2. Poll until the request leaves the queue / in-progress state while true; do STATUS=$(curl --silent --url "$STATUS_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" | jq -r '.status') echo "Status: $STATUS" case "$STATUS" in COMPLETED) break ;; FAILED|CANCELLED) echo "Request $STATUS"; exit 1 ;; esac sleep 1 done # 3. Read the finished request, including the generated output curl --silent --url "$RESPONSE_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" ``` ### JavaScript ```javascript import { modelrunner } from "@modelrunner/client"; const result = await modelrunner.subscribe("google/gemini-3.7-flash", { input: { "messages": [ { "role": "user", "content": "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." } ], "max_tokens": 8000, "reasoning_effort": "high" } }); console.log(result.data); ``` ### Python ```python import asyncio import modelrunner_ai async def main(): response = await modelrunner_ai.submit_async( "google/gemini-3.7-flash", arguments={ "messages": [ { "role": "user", "content": "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." } ], "max_tokens": 8000, "reasoning_effort": "high" } ) result = await response.get() print(result["output"]) asyncio.run(main()) ``` ## Additional Resources - [Playground](https://modelrunner.ai/models/google/gemini-3.7-flash) - [OpenAPI Schema](https://modelrunner.ai/models/google/gemini-3.7-flash/openapi.json) - [LLM Instructions](https://modelrunner.ai/models/google/gemini-3.7-flash/llms.txt)