OverpayingForAIPricing desk
9 min read·Last reviewed for accuracy · 2026-09-11·Prices verified · 2026-09-12

Gemini API Function Calling Cost: Gemini Agent Pricing Guide

What a Gemini agent costs to run: Gemini 3.1 Pro, 3.8 Flash and 3.5 Flash Lite on a function-calling loop, why 1M context is a cost trap, context caching and batch, the free tier, and Google AI Pro and Ultra versus the API.

The article text carries the review date. The rate table below is rebuilt from the live catalogue on every deploy.

Fastest win

Gemini 3.8 Flash at $0.75 in / $3.75 out per 1M tokens runs a 12-step function-calling loop for about $0.14, or roughly $0.06 with context caching, and is the best-value agent model in Google's range. The 1M context window is the trap: an agent that drags 500,000 tokens of documents through 12 steps sends 6M input tokens and costs $12 per run on Gemini 3.1 Pro before any output.

Gemini agent cost: the direct answer

A 12-step function-calling agent costs $0.377 on Gemini 3.1 Pro ($2 in / $12 out per 1M tokens), $0.139 on Gemini 3.8 Flash ($0.75 / $3.75) and $0.059 on Gemini 3.5 Flash Lite ($0.30 / $2.50), using a 4,000-token system instruction plus function declarations, 1,500-token function responses and 300 output tokens per step. Those steps add up to 166,800 input tokens and 3,600 output tokens because each step re-sends the whole history. Prices are from our catalogue dated 2026-09-11.

Model$/1M in / outContext5-step12-step30-step12-step cached (approx.)
Gemini 3.1 Pro$2 / $121M$0.094$0.377$1.914$0.16
Gemini 3.8 Flash$0.75 / $3.751M$0.034$0.139$0.711$0.06
Gemini 3.5 Flash Lite$0.30 / $2.501M$0.015$0.059$0.293$0.03

For Gemini 3.8 Flash at 12 steps: 166,800 × $0.75 ÷ 1,000,000 = $0.125 input, plus 3,600 × $3.75 ÷ 1,000,000 = $0.0135 output, total $0.139. There is no per-call function-calling fee; declarations, calls and responses are ordinary tokens. Google's built-in grounding and search tools are priced separately (see the vendor page).

How a Gemini function-calling loop spends tokens

With the google-genai SDK you pass Python functions or FunctionDeclaration objects in config.tools. The model returns a function_call part, you run it and append a function_response part, and call generate_content again with the full contents list. Automatic function calling in the SDK will run that loop for you, which is also the fastest way to spend money without noticing, so set maximum_remote_calls on AutomaticFunctionCallingConfig rather than accepting the default.

On Gemini 3.8 Flash the input side is 90% of the bill, and on Gemini 3.1 Pro 88%. Doubling every assistant turn on 3.1 Pro adds $0.043 to a $0.377 run. Gemini models reason by default and reasoning tokens bill as output; use thinking_config to lower the thinking budget on Flash and Flash Lite workers. Cached tokens are reported in usage_metadata.cached_content_token_count, which is what to watch to confirm caching is working.

Why the 1M context window is a cost trap for agents

All three current Gemini models accept about 1M tokens per request, and the temptation is to load an entire codebase, contract set or crawl into the first turn and let the agent work. The context window is a capacity limit, not a discount, and an agent re-sends that context on every step.

The arithmetic: an agent carrying 500,000 tokens of documents through a 12-step loop sends 12 × 500,000 = 6,000,000 input tokens for the documents alone. At $2 per 1M on Gemini 3.1 Pro that is $12.00 per run before tool traffic or output. On Gemini 3.8 Flash it is $4.50, on 3.5 Flash Lite $1.80. The same task as a retrieval agent pulling 5,000 relevant tokens per step costs about $0.45 on 3.1 Pro.

The trap has a second jaw: latency. Half a million tokens per step turns a two-minute agent into a twenty-minute one. Treat 1M context as the ceiling for a single reading pass, not as working memory for a loop; if the documents genuinely must be present every step, that is the case for context caching.

Context caching: roughly 25% of list for the repeated prefix

Gemini's context caching lets you upload a large prefix once, get a cache name back, and reference it on each call. Cached input tokens bill at roughly 25% of the list input rate, a smaller discount than Anthropic's or OpenAI's roughly 10%, plus a storage charge per token-hour that is not in our catalogue (see the vendor page).

The 500,000-token document case becomes one full-price ingestion ($1.00 on 3.1 Pro), then 12 cached reads at roughly $0.25 each instead of $1.00, so about $4 per run instead of $12, plus storage. On the reference 12-step trace with system instruction and functions cached, 3.1 Pro lands at roughly $0.16 instead of $0.377 and 3.8 Flash at roughly $0.06 instead of $0.139.

from google import genai
from google.genai import types

client = genai.Client()

def lookup_shipment(tracking_id: str) -> dict:
    """Return the current status for a shipment tracking id."""
    return wms.status(tracking_id)

cache = client.caches.create(
    model="gemini-3.8-flash",
    config=types.CreateCachedContentConfig(
        system_instruction=SYSTEM_PROMPT,
        contents=[types.Content(role="user", parts=[types.Part(text=POLICY_DOCS)])],
        ttl="3600s",
    ),
)
resp = client.models.generate_content(
    model="gemini-3.8-flash",
    contents=history,
    config=types.GenerateContentConfig(
        cached_content=cache.name,
        tools=[lookup_shipment],
        automatic_function_calling=types.AutomaticFunctionCallingConfig(maximum_remote_calls=12),
        max_output_tokens=2000,
    ),
)
m = resp.usage_metadata
# 3.8 Flash: $0.75 in, ~$0.19 cached in, $3.75 out per 1M (+ cache storage, vendor page)
cost = ((m.prompt_token_count - m.cached_content_token_count) * 0.75
        + m.cached_content_token_count * 0.19 + m.candidates_token_count * 3.75) / 1_000_000

Because the discount is only 75%, the storage fee can erase it on short runs; do the sum for your own TTL. The prompt caching cost comparison has the three vendors side by side.

Batch mode: half price for fan-out work

Gemini's batch mode runs requests asynchronously at roughly 50% of list, and our catalogue carries batch rows for the Gemini models at that rate (Gemini 3.8 Flash batch at about $0.375 / $1.875 per 1M). A live loop cannot use it, since step two needs step one's function response, but the fan-out around an agent can: classifying 20,000 support emails before an agent handles the hard ones. At list a 5-step Gemini 3.8 Flash agent costs $0.034 per item, so 20,000 items cost $680; in batch about $340. See LLM batch API pricing for the cross-vendor comparison.

The free tier, and the consumer plans versus the API

The Gemini API free tier is the cheapest place to prototype an agent: $0, the same models and function-calling surface as the paid tier, and rate limits sufficient to iterate on a loop with a handful of tools. Two cautions: a 30-step loop will hit those limits, and the free tier's data-use terms differ from the paid tier's, so move to pay-as-you-go before the agent touches real data.

The consumer plans, Google AI Pro at $19.99 and Google AI Ultra at $249 a month, are not API plans. They buy the Gemini app with the Pro model, Gemini in Workspace, extra storage and higher limits in Google's own coding tools; they do not credit an API bill. So the comparison only holds for a person driving an agent interactively.

PlanMonthly price3.8 Flash runs at $0.14 (uncached)3.1 Pro runs at $0.38 (uncached)
Gemini API free tier$0rate-limitedrate-limited
Google AI Pro$19.99~143~53
Google AI Ultra$249~1,790~660

An individual who wants Gemini for chat, documents and some coding assistance should buy AI Pro. Ultra at $249 only makes sense for someone whose interactive use would otherwise equal 660 uncached Pro-class runs a month; the same $249 on the API buys about 4,000 cached Gemini 3.8 Flash runs. Our Gemini pricing page has the plan details.

Cheapest reliable Gemini for agents, and when to pay for 3.1 Pro

The cheapest model that still does this reliably: Gemini 3.8 Flash. At $0.139 per 12-step run it follows function declarations consistently, handles 1M context, supports caching, and finishes routine tasks in about the same number of steps as 3.1 Pro. It is our default for worker agents on Google's stack, level with GPT-5.4 mini ($0.141) and cheaper than Claude Haiku 4.5 ($0.185) on the same trace.

Gemini 3.5 Flash Lite at $0.059 suits classify-and-route steps and small tool sets, but its step count blows out on open-ended tasks, and 30 Flash Lite steps ($0.293) cost more than 12 Flash steps. Keep it off the planner role.

When to pay for Gemini 3.1 Pro: at $0.377 per run it is 2.7× Flash, so it needs to fail materially less often or finish in materially fewer steps. That holds for multi-document reasoning, planning across a large tool set, and anything where a wrong function call has side effects. As a planner delegating to Flash workers it is worth the money; for every step of a simple loop it is not. The cheapest LLM for agents guide ranks all three against 27 other models.

How to cap spend on a Gemini agent

Four controls that each catch a different failure:

  • max_output_tokens in GenerateContentConfig: 1,000 to 4,000 for function-calling turns, paired with a thinking budget so reasoning tokens are bounded too.
  • maximum_remote_calls on AutomaticFunctionCallingConfig, or a manual step counter: 12 to 15 for most tasks.
  • Stop conditions: a required finish function, an abort on two identical consecutive function calls, and a cap on context tokens per step (say 60,000) that forces older function responses to be summarised or dropped.
  • A per-run USD budget computed from usage_metadata after each call, with cached tokens at roughly 25% of list. Abort past the ceiling and record it per task to compute cost per successful task.

At Gemini 3.8 Flash rates a $0.25 per-run budget allows about 17 uncached reference steps or roughly 40 cached; on 3.1 Pro the same budget buys about 9 uncached steps. The AI cost calculator converts a monthly run count into a budget, the Gemini 101 tutorial covers the SDK basics, and the Claude agent API cost and OpenAI Agents SDK cost guides cover the other stacks.

Key Takeaways

  • A 12-step Gemini agent run costs $0.38 on Gemini 3.1 Pro, $0.14 on Gemini 3.8 Flash and $0.06 on Gemini 3.5 Flash Lite before caching
  • The 1M context window is a capacity limit, not a discount: carrying 500,000 tokens through 12 steps sends 6M input tokens, $12 per run on 3.1 Pro
  • Gemini context caching bills roughly 25% of list input plus a storage fee, a smaller discount than Anthropic or OpenAI's roughly 10%
  • Batch mode runs at roughly 50% of list for fan-out work and stacks with caching
  • Google AI Pro ($19.99) and Ultra ($249) do not include API credit; the free tier is for prototyping only
  • Default to Gemini 3.8 Flash for workers, pay for 3.1 Pro as a planner, keep Flash Lite off open-ended tasks

Editorial context

Who is this for?

Developers building function-calling agents on the Gemini API with the google-genai SDK who need a per-run cost, and teams weighing Google AI Pro or Ultra against pay-as-you-go API billing.

When NOT to use this

Consumers choosing between the Gemini app's free and paid tiers; buyers who only need a cross-vendor ranking, which the cheapest LLM for agents guide provides.

Pricing insights

Gemini 3.8 Flash at $0.14 per 12-step run matches GPT-5.4 mini and undercuts Claude Haiku 4.5, but the 1M window invites context bloat that multiplies cost by the step count, and Gemini's caching discount at roughly 25% of list is weaker than its rivals' roughly 10%.

Alternatives to consider

GPT-5.4 mini at $0.75/$4.50 or Claude Haiku 4.5 at $1/$5 for the Flash tier; Claude Sonnet 5 at $2/$10 or GPT-5.4 at $2.50/$15 for the 3.1 Pro tier; the Gemini free tier for prototyping.

Final verdict

Run workers on Gemini 3.8 Flash, use 3.1 Pro only as a planner, retrieve instead of carrying documents through the loop, cache anything that must persist, and treat the consumer plans as irrelevant to API cost.

Frequently Asked Questions

How much does Gemini API function calling cost?

There is no per-call fee; function declarations, calls and responses are billed as ordinary tokens. On a 12-step loop with a 4,000-token system instruction and functions, 1,500-token function responses and 300 output tokens per step, a run costs $0.377 on Gemini 3.1 Pro, $0.139 on Gemini 3.8 Flash and $0.059 on Gemini 3.5 Flash Lite.

Which Gemini model is best for agents on a budget?

Gemini 3.8 Flash at $0.75 in / $3.75 out per 1M. It follows function declarations reliably, supports 1M context and caching, and costs about $0.14 per 12-step run, roughly $0.06 cached. Gemini 3.5 Flash Lite is cheaper per token but takes more steps on open-ended tasks, which erases its advantage.

Why is the 1M context window expensive for agents?

Because an agent re-sends its context on every step. Carrying 500,000 tokens of documents through 12 steps sends 6,000,000 input tokens, which is $12 on Gemini 3.1 Pro or $4.50 on Gemini 3.8 Flash per run before any output. Use retrieval to pull a few thousand relevant tokens per step, or cache the documents if they must be present every step.

How does Gemini context caching pricing work?

You create a cache from a large prefix and reference it on each call. Cached input tokens bill at roughly 25% of the list input rate, plus a per-token-hour storage charge listed on the vendor page. On the reference 12-step trace that takes Gemini 3.1 Pro from $0.377 to roughly $0.16, though on short runs the storage fee can cancel the saving.

Can I build an agent on the Gemini API free tier?

For prototyping, yes: it costs $0 and exposes the same models and function calling as the paid tier. Rate limits are low enough that long loops hit them, and the free tier's data-use terms differ from the paid tier's, so move to pay-as-you-go before the agent handles real data.

Does Google AI Pro or Ultra include Gemini API usage?

No. Google AI Pro at $19.99 and Google AI Ultra at $249 a month buy the Gemini app, Gemini in Workspace, storage and higher limits in Google's own tools, not API credit. For a person using Gemini interactively AI Pro is good value; any unattended or product agent pays API rates, where $249 buys roughly 4,000 cached Gemini 3.8 Flash runs.

Related

Free courses · no sign-up

Still deciding? Learn the basics first, then come back to the prices.

If our calculators helped you cut down on hidden AI wallet leaks, thanks for using them. A tiny fraction of your savings is what keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.