{"slug": "how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of", "title": "How to Call Gemini 4 Argon with the OpenAI SDK: Streaming, reasoning_effort and the Real Cost of Each Request", "summary": "A developer at API gateway apimodels.app published a guide showing how to call Google's Gemini 4 Argon reasoning model through the OpenAI Python SDK by swapping the base_url, covering streaming, the reasoning_effort parameter, and per-request cost tracking. The writeup notes that Argon always reasons before answering and that Google bills thinking tokens at the output rate, with the author's own tests showing a one-word \"OK\" reply consumed 66 thinking tokens on 14 October 2026, and 105 at low versus 302 at high effort the next day. The author recommends setting thinking levels deliberately and reading reasoning_tokens from every response, since high-effort prompts ran 8 to 10 minutes.", "body_md": "You send Gemini 4 Argon a one-line question, get a one-word answer, and the usage block says you paid for about 70 output tokens. That is not a bug. Argon thinks before every answer, and thinking is billed as output.\n\nGemini 4 Argon (`gemini-4-argon`) is Google's flagship reasoning model, available on the paid tier of the Gemini API since 13 October 2026, with a 1M-token context window shared by input and output and up to 65,536 output tokens per response. This tutorial calls it through an OpenAI-compatible endpoint with the official `openai` Python package, streams long answers, sets the thinking level with `reasoning_effort`, and reads back exactly what each request cost.\n\nDisclosure up front: the endpoint in the examples is apimodels.app, the API gateway I work on. The same code runs against Google's own OpenAI-compatible endpoint if you swap the base URL; I note the differences where they matter. This post was drafted with AI assistance from our docs and test notes, and every command was checked against those sources.\n\n`pip install openai`\n`curl` for the first check\n\n```\nexport APIMODELS_API_KEY=\"sk_your_key_here\"\n```\n\n`https://api.apimodels.app/v1` (with Google directly, it is `https://generativelanguage.googleapis.com/v1beta/openai/` and a Gemini API key)\nArgon always reasons before it answers, and Google bills those thinking tokens at the output rate. Google's pricing page says it plainly: \"Output price (including thinking tokens)\". [Google's thinking guide](https://ai.google.dev/gemini-api/docs/thinking) lists three levels for Argon (low, medium, high), sets medium as the default, and thinking cannot be turned off.\n\nOur own measurements show the effect. On 14 October 2026, asking Argon to reply with just \"OK\" used 66 thinking tokens. On 15 October, the same prompt used 105 thinking tokens at `low` and 302 at `high`. On one hard reasoning prompt, `high` ran for 8 to 10 minutes. So two habits matter from the first line of code: set the thinking level on purpose, and read the thinking count from every response.\n\nThis request asks a short question at the lowest thinking level, which keeps the first test fast.\n\n```\ncurl https://api.apimodels.app/v1/chat/completions \\\n  -H \"Authorization: Bearer $APIMODELS_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"model\": \"gemini-4-argon\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"In one sentence: what does a database index trade off?\"}],\n    \"reasoning_effort\": \"low\",\n    \"max_tokens\": 4000\n  }'\n```\n\nYou get a standard chat-completion object. Look at `usage`: `completion_tokens` already includes thinking, and `completion_tokens_details.reasoning_tokens` tells you how much of it was thinking.\n\nThe OpenAI SDK needs only a different `base_url`. Using `with_raw_response` keeps the response headers, which carry the request ID and, for non-streaming calls on apimodels.app, the amount charged.\n\n``` python\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=os.environ[\"APIMODELS_API_KEY\"],\n    base_url=\"https://api.apimodels.app/v1\",\n    timeout=900,  # high-effort runs can take minutes\n)\n\nraw = client.chat.completions.with_raw_response.create(\n    model=\"gemini-4-argon\",\n    messages=[{\"role\": \"user\", \"content\": \"Explain the N+1 query problem in two sentences.\"}],\n    reasoning_effort=\"low\",\n    max_tokens=4000,\n)\nresp = raw.parse()\nprint(resp.choices[0].message.content)\n\nu = resp.usage\nthinking = getattr(u.completion_tokens_details, \"reasoning_tokens\", 0) or 0\nprint(\"input:\", u.prompt_tokens, \"| output incl. thinking:\", u.completion_tokens, \"| thinking:\", thinking)\nprint(\"request id:\", raw.headers.get(\"x-apimodels-request-id\"))\nprint(\"charged (USD):\", raw.headers.get(\"x-apimodels-cost\"))\n```\n\nThe last two lines are apimodels.app-specific headers; with Google directly they are absent and you calculate cost from `usage` yourself.\n\nStreaming is the safe default for Argon, because a long, high-effort answer can take minutes. Ask for usage in the final chunk with `stream_options`.\n\n```\nstream = client.chat.completions.create(\n    model=\"gemini-4-argon\",\n    messages=[{\"role\": \"user\", \"content\": \"Write a step-by-step plan to migrate a Flask app from SQLAlchemy 1.4 to 2.0.\"}],\n    reasoning_effort=\"medium\",\n    stream=True,\n    stream_options={\"include_usage\": True},\n)\n\nusage = None\nfor chunk in stream:\n    if chunk.choices and chunk.choices[0].delta.content:\n        print(chunk.choices[0].delta.content, end=\"\", flush=True)\n    if chunk.usage:\n        usage = chunk.usage\n\nprint(\"\\n\\nusage:\", usage)\n```\n\nIn one test on 15 October 2026, a stream of 16,599 output tokens took 144 seconds, with the first token after 8.7 seconds, about 120 tokens per second after that. On api.apimodels.app a streamed Argon response can run for up to 30 minutes; a non-streaming request is cut off at 13 minutes (limits as of 17 October 2026). Use the `api.apimodels.app` host for long jobs.\n\n`reasoning_effort` maps to Argon's three thinking levels. apimodels.app sends `none` and `minimal` as `low` (Argon cannot turn thinking off), `medium` as `medium`, and `high`, `xhigh` and `max` as `high`; any other value is dropped and the model's default (medium) applies. Google's own OpenAI-compatible endpoint maps `minimal` to `low` for Argon as well.\n\nA practical split:\n\nDo not use `max_tokens` as your cost control. Google's docs warn that when the limit is hit during reasoning, the answer can come back truncated or empty while the thinking tokens are still billed. Lower the thinking level instead, and keep `max_tokens` generous. The ceiling for a normal request is 65,536; anything above that returns a 400 error.\n\nTool calling works through the same endpoint: in our tests on 15 October 2026, single tools, three parallel tools, streaming and multi-turn tool conversations all passed. One schema detail trips people up. Some JSON Schema generators add a top-level `\"$schema\"` key, and Gemini rejects it:\n\n```\nInvalid JSON payload received. Unknown name \"$schema\" at 'tools[0].function_declarations[0].parameters'\n```\n\nStrip it before you send the tool definition:\n\n``` php\ndef clean_parameters(schema: dict) -> dict:\n    schema = dict(schema)\n    schema.pop(\"$schema\", None)\n    return schema\n```\n\nEvery successful LLM response from apimodels.app carries an `x-apimodels-request-id` header, streaming included. Pass that ID to the records endpoint to get the settled amount.\n\n```\ncurl https://api.apimodels.app/v1/records/<request-id> \\\n  -H \"Authorization: Bearer $APIMODELS_API_KEY\"\n```\n\nWhen `data.settled` is `true`, `data.credits` is the final USD amount taken from your balance, and `data.usage` holds the token counts. A failed request always shows 0, and the lookup itself is free.\n\napimodels.app is a multi-model API gateway: one API key and an OpenAI-compatible endpoint, plus native Gemini and Anthropic formats, for more than 140 image, video, audio and language models. For Argon that means more than one upstream channel with automatic failover, no charge for failed requests, and the per-request lookup above. As of 17 October 2026 Argon costs $1.10 per million input tokens and $5.50 per million output there, 55% of Google's $2 / $10 list. Google's list rises to $4 / $20 on 1 December 2026, and apimodels.app moves to $2.20 / $11.00 at 00:00 UTC that day, still 55%, with no code change. Argon supports Google's implicit caching only: explicit cache objects are not supported, and whether a repeated prefix hits is decided on Google's side and is not guaranteed. Cached tokens bill at $0.055 per million ($0.11 from 1 December), but budget as if nothing is cached. Details are on the [Gemini 4 Argon model page](https://apimodels.app/models/gemini-4-argon?utm_source=dev).\n\nSkip it if you need more than 65,536 output tokens in one answer: that is Google's long-decode mode, which needs Google's background execution API, and apimodels.app does not expose it. Skip it too if you need a contract, compliance terms or provisioned throughput directly with Google.\n\n`Invalid JSON payload received. Unknown name \"$schema\"``$schema` key. Remove it (Step 5).`content` with `finish_reason: \"length\"`` max_tokens`. Raise `reasoning_effort`.` Authorization: Bearer <key>`.` stream=True`, or raise the SDK timeout for non-streaming calls.\n**Does reasoning_effort work with Gemini 4 Argon?** Yes. It maps to Argon's thinking levels low, medium and high, and it changes the bill: the same prompt used 105 thinking tokens at low and 302 at high in our test. Argon cannot turn thinking off, so `none` behaves like `low`. Set it per request rather than globally, and use `high` only for work that runs in the background.\n\n**How do I know what a single Argon request cost?** Read `usage.completion_tokens` (thinking included) and `usage.prompt_tokens` from the response. On apimodels.app, non-streaming responses also carry the charged amount in `x-apimodels-cost`, and `GET /v1/records/{id}` returns the settled amount for any request, streaming or not.\n\nWhat do you set `reasoning_effort` to for coding agents: one global level, or per task?\n\n*This post was written with AI assistance from apimodels.app's docs and our test notes, and reviewed before publishing. I work on apimodels.app.*", "url": "https://wpnews.pro/news/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of", "canonical_source": "https://dev.to/super_lewis/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoningeffort-and-the-real-cost-of-4h8n", "published_at": "2026-10-17 15:27:14+00:00", "updated_at": "2026-10-17 15:34:25.300561+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "ai-products"], "entities": ["Google", "Gemini 4 Argon", "OpenAI", "apimodels.app", "Gemini API"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of", "markdown": "https://wpnews.pro/news/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of.md", "text": "https://wpnews.pro/news/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of.txt", "jsonld": "https://wpnews.pro/news/how-to-call-gemini-4-argon-with-the-openai-sdk-streaming-reasoning-effort-and-of.jsonld"}}