Models API

Gemini API with live pricing, in Google's own format

Call Gemini through the native Gemini API with generateContent, SSE streaming, countTokens and the Gemini CLI. One prepaid key, billed per token.

Prepaid, no subscriptionREST or MCPOne key for models, data and agents
Gemini CLIGoogle GenAI S…Your appAgentslovely1 keyClaude/v1/messagesclaude-opus-5.5claude-sonnet-5.5claude-haiku-5.5GPT/v1/responsesgpt-6.1-solgpt-6-astragpt-5.6-terraGemini/v1betagemini-3.1-progemini-3.8-flashgemini-3-flash

Gemini code is written in Google's format: contents and parts, systemInstruction, generationConfig, thinkingConfig. Lovely Router serves that format under /v1beta/models/{model}, so the Google Gen AI SDK and the Gemini CLI work with a new base URL and your Lovely Router key in place of a Gemini API key. Your request reaches the model as you wrote it, apart from the model id, and the same prepaid key also calls Claude, GPT and the data tools.

Hand it to your AI agent

Copy this prompt into Claude Code, Cursor, Codex or any coding agent. It tells the agent where the docs are and how to use your API key.

Integrate models from Lovely Router into this project through the native Gemini API.

- Docs (read first): https://lovelyrouter.com/docs/models/gemini.md
- Use the Google GenAI SDK with base URL https://lovelyrouter.com (http_options / httpOptions `baseUrl`, or GOOGLE_GEMINI_BASE_URL=https://lovelyrouter.com). Endpoints: https://lovelyrouter.com/v1beta/models/<model>:generateContent and :streamGenerateContent, unchanged from Google.
- GET https://lovelyrouter.com/v1/models lists every model id with its price; pick one there, do not guess ids.
- Auth: read my API key from the LOVELY_API_KEY environment variable and send it as `x-goog-api-key: $LOVELY_API_KEY`. Never print or commit the key. If it is not set, ask me to create one at https://lovelyrouter.com/app/keys.
- Billing is prepaid: every call is charged to my balance, so test with a small request before running anything large.
- Every docs page is plain Markdown; the full index is https://lovelyrouter.com/llms.txt.

My task: <describe what you want to build or get>
01

How it works

010203
  1. Create a key

    Sign up, add credit from $5, and create a key in API keys. Give keys that run unattended a spend limit.

  2. Point the Gen AI SDK at Lovely Router

    Pass https://lovelyrouter.com as the SDK's base URL. The key goes in x-goog-api-key, which the SDKs send; ?key= and Authorization: Bearer work too.

  3. Call generateContent

    generateContent, streamGenerateContent and countTokens behave as Google documents them.

    curl "https://lovelyrouter.com/v1beta/models/gemini-3.1-pro:generateContent" \
      -H "x-goog-api-key: $LOVELY_API_KEY" \
      -H "content-type: application/json" \
      -d '{
        "contents": [{"role": "user", "parts": [{"text": "Explain DNS in two sentences."}]}]
      }'
02

Gemini API pricing, live

ModelContextInputOutputCache read
Gemini 3.1 Pro
gemini-3.1-pro
1.05M$2.00$12.00$0.20
Gemini 3 Flash
gemini-3-flash
1.05M$0.50$3.00$0.05
Gemini 4 Argon
gemini-4-argon
1.05M$2.00$10.00$0.20
Gemini 3.5 Flash
gemini-3.5-flash
1.05M$1.50$9.00$0.15
Gemini 3.8 Flash
gemini-3.8-flash
1.05M$0.75$3.75$0.075
Gemini 3.6 Flash
gemini-3.6-flash
1.05M$0.75$3.75$0.075

USD per 1M tokens, live from the catalog.

Prices are in US dollars per million tokens, from the live catalog. Ids follow GET /v1/models, for example gemini-3.1-pro and gemini-3-flash, and Google's spellings such as gemini-3.1-pro-preview or models/gemini-3-flash resolve to the same model. GET /v1beta/models lists every model available in this format, in Gemini's own response shape. Gemini models are served in the gemini-value channel group; the model marketplace shows live availability and status hour-by-hour availability per channel group.

03

What the native API gives you

SSE streaming

Call :streamGenerateContent?alt=sse; the SDKs add alt=sse for you. Each event is a partial GenerateContentResponse, and the last one carries the final usageMetadata.

Thinking

Gemini 3 models think by default. Adjust it with thinkingConfig as Google documents. Thinking tokens appear in usageMetadata.thoughtsTokenCount.

Everything else in the request

systemInstruction, generationConfig, safetySettings and function declarations in tools pass through unchanged.

Free token counts

:countTokens takes the same contents and returns totalTokens. It costs nothing and works with a zero balance.

These Gemini endpoints are not served: cachedContents (explicit context caching), file uploads, embedContent and batchEmbedContents, batch mode and the Live API.

Gemini models also accept OpenAI Chat Completions and Anthropic Messages, which helps when your app only speaks one of those. thinkingConfig and other Gemini-only options are only certain to work in the native format.

04

Use the Gemini CLI

search_toolsrun_toolget_run

The Gemini CLI reads its endpoint and key from the environment:

Shell
export GOOGLE_GEMINI_BASE_URL=https://lovelyrouter.com
export GEMINI_API_KEY=$LOVELY_API_KEY
gemini -m gemini-3.1-pro

Use with your tools covers other clients, and AI coding agents shows the Gemini CLI next to Claude Code and Codex CLI on the same key.

05

Implicit caching, kept warm

Gemini caches repeated prompt prefixes on its own, with nothing to mark. Cached tokens appear in usageMetadata.cachedContentTokenCount and are billed at the cache-read price, with no cache-write charge.

A cache only helps if the next turn reaches the channel that holds it. Lovely Router fingerprints each conversation from its system prompt and first user message and sends later turns back to the same channel. If your app rewrites or summarizes old history, send a stable x-session-id header per conversation instead. A timestamp in the system instruction breaks both the fingerprint and Gemini's own cache, so put it in the latest user message. Details are in Prompt caching.

06

When a channel fails

Failures you would otherwise handle yourself are retried by the gateway first. A request that fails on a channel is retried on another one in the same group, up to three attempts, and a stream is held until its first token, so a failure before that point is retried instead of reaching you. What remains comes back in Gemini's error shape: RESOURCE_EXHAUSTED for 429 and UNAVAILABLE for 502. Retry those with backoff, and honor retry-after when it is present. Invalid requests (400, 404, 413, 422) are not retried, because they would fail the same way elsewhere.

Prefer alt=sse. Without it, streamGenerateContent returns one JSON array; with it, a stream that stalls for three minutes ends with a clean DEADLINE_EXCEEDED error event you can detect. Rate limits & failover has the full table.

07

Recipes

Plan with a system instruction

Call gemini-3.1-pro with system_instruction and max_output_tokens in GenerateContentConfig, then read usage_metadata for the cost.

Stream into a chat UI

Use generate_content_stream on gemini-3-flash and render each chunk's text as it arrives.

Check a large prompt first

Run count_tokens on the same contents and compare total_tokens with the model's context length before you pay for a call.

Run the Gemini CLI on a budget

Create a key with a spend limit just for the CLI, so a long session can't spend past it.

Pin keys to one group

Bind a production key to gemini-value, or send x-lovely-group, and every retry stays in that group at the same price.

08

What you pay

Gemini is billed per token. Uncached input is promptTokenCount minus cachedContentTokenCount; cached tokens are billed at the cache-read price; output is candidatesTokenCount plus thoughtsTokenCount, at the output price. Every channel group bills at list price today, so each Gemini model costs what Google lists. Charges are deducted from your prepaid balance within seconds of the response.

There is no subscription and no monthly fee. Requests refused before reaching a model cost nothing, retried attempts are not billed, and a stream you cancel pays only for what it produced. Pricing shows every product on one page.

09

Frequently asked questions

?
Does the Google Gen AI SDK work with Lovely Router?+

Yes. Pass https://lovelyrouter.com as the base URL in http_options (Python) or httpOptions (Node.js) and your Lovely Router key as the API key. Request bodies pass through unchanged.

Can I use the Gemini CLI?+

Yes. Set GOOGLE_GEMINI_BASE_URL to https://lovelyrouter.com and GEMINI_API_KEY to your key, then start it with gemini -m gemini-3.1-pro.

Which Gemini models can I call?+

Gemini Pro and Gemini Flash models, such as gemini-3.1-pro and gemini-3-flash. GET /v1beta/models lists every model available in this format.

How are thinking tokens billed?+

Thinking tokens are reported in usageMetadata.thoughtsTokenCount and billed at the output rate, together with candidatesTokenCount.

Is context caching supported?+

Implicit caching is: repeated prefixes are cached by Gemini and billed at the cache-read price, and the gateway keeps each conversation on one channel. Explicit caching through the cachedContents API is not available.

Can I call Gemini through the OpenAI SDK?+

Yes. Gemini models accept OpenAI Chat Completions with the same key. Use the native Gemini API when you need thinkingConfig or other Gemini-only options.

Read the Gemini guide for every method and header, or compare all vendors in the model marketplace.

One prepaid key for models, data and agents

No subscription. Top up, use what you need, see every charge in your logs.