Own Weights

How to reduce Gemini API costs, and when to leave the API

Ways to reduce Gemini API costs: caching, batching and shorter outputs, then when a trained model you own is cheaper per document and how to test it.

Updated

To reduce Gemini API costs, cut the tokens you send and the tokens you get back, use the batch and caching options Google offers, and stop paying for calls that do not change the answer. If one task runs at high volume, a trained model you run in your own cloud account can cost less per document, but you should switch only after it beats the current model on your own test.

Why is the Gemini API too expensive for one task?

A frontier model is built to handle everything. You pay for that range on every call, even when the job is one fixed thing, such as pulling payment terms out of invoices or tagging support tickets. Most bills grow in a straight line with volume. Twice the documents means roughly twice the bill.

Three things drive the line. Input tokens come first: long system prompts, full documents sent when one section would do, and chat history nobody needs. Output tokens come next. Output usually costs more per token than input, so a model that writes paragraphs when you wanted one field value is expensive. The third is waste: retries after a failed parse, timeouts that re-run the whole request, and agent loops that call the model again on its own output.

Gemini API cost optimization: what to change first

Work in this order. Each step is cheap to try, and the first one shows where the money goes.

  1. Log tokens per call. Record input and output tokens for each feature and call site. Look for the few call sites that make up most of the bill.
  2. Cut the input. Remove repeated boilerplate from the system prompt and send only the part of a document the task needs.
  3. Cap and structure the output. Set a maximum output length and ask for a fixed JSON schema, so the model returns the fields you need and nothing else.
  4. Cache the repeated prefix. If every call starts with the same instructions or reference text, Gemini’s context caching can bill that prefix at a lower rate. The terms change, so read the current Gemini pricing page before you plan around it.
  5. Batch work that can wait. Backfills, overnight re-tagging and bulk review do not need an instant reply. Google’s batch options can be priced below real-time calls. Check the pricing page for the exact rate.
  6. Stop repeat and failed calls. Store answers to questions you have already answered, and fix the parsing bug behind the retries.
  7. Use the smallest tier that passes. Test each Gemini tier on your own data, and move a feature down only when the smaller tier still gets it right.

Our guides on prompt caching savings and batch API timing go deeper on the two biggest levers.

When is a cheaper alternative to the Gemini API a trained model?

Those levers lower the bill, but the bill still scales with tokens. The other option changes the shape of the cost. Own Weights takes one high-volume task, fine-tunes an open-weight model on examples from your own records, tests it against the current model, and serves it in your own cloud account or on-prem. You own the weights. The cost becomes compute you run, not tokens you buy on every call.

We ran this on a public exam: 510 commercial contracts, with exact passages marked by lawyers. Our Accuracy model scored 0.717 and our Standard model 0.650, where 1.0 is perfect. Claude Opus scored 0.635 and Claude Haiku 0.584. Our lead is +0.082 over Opus and +0.133 over Haiku, both larger than the margin of error. We were ahead of both in all 5 groups of 102 documents. Scoring used 5-fold cross-validation, so every document was scored by a model that never saw it in training. Full results are on the benchmark page.

Two caveats matter. Our models were fine-tuned for this exam, while Claude took it with one prompt, no examples and no task training. That shows what training for one task does. It is not a legal product or legal advice, and it does not mean our model beats Claude at everything. Fine-tuned models beat frontier models on the exam we ran, and they can on a narrow task with good data. They do not always win.

On the same exam, the price was $4.50 per 1,000 documents for our Accuracy tier, $3.54 for our Standard tier, $4.95 for Claude Haiku and $154.49 for Claude Opus at list price. We ran this against Claude, not Gemini, so we have no Gemini figure to give you. Compare against your own invoices.

Trained models are not always the right move. Skip them when volume is low, when the task changes every few weeks, when you need broad reasoning across many subjects, or when you have no clean examples of right answers. Hypothetically, a feature that sends 100,000 short classification calls a day with stable labels is a better candidate than a general assistant. Hosting also means you own the upkeep: monitoring, updates and retraining.

Why are Vertex AI costs too high, and where do you look first?

Vertex AI bills model tokens, and your Google Cloud project can add other charges around them. Before you change code, break the bill down by project, by model and by feature label. A single endpoint with steady traffic is the best first candidate for the test below. Check Google Cloud’s pricing page for current terms, since each service has its own rules.

How do you test a cheaper option before you switch?

Build the test from your real data, not a demo set. Score the current model first, then train and score the candidate on the same fixed set. Deploy only if the candidate beats the current model on that test. Keep the test fixed, so later comparisons still mean something. This is the step that stops a cheap model from quietly getting worse. Our LLM evaluation guide covers the method, and migrating one task off a frontier API covers the cutover.

If one task makes up most of your bill, start with the free AI cost audit. It reads your code on your own machine, makes no network calls while it reads, uploads nothing, and saves a PDF listing your AI calls, models, estimated cost and common problems. If you would rather talk it through, book a call and we will look at the numbers with you.

Questions

Why is the Gemini API too expensive?

Gemini bills scale with tokens, so the cost rises with every call you make. Long prompts, verbose output and retries add to the total on each request, which is why a steady feature can cost far more than it looks like it should.

What is a cheaper alternative to the Gemini API?

For one high-volume task, a fine-tuned open-weight model served in your own cloud account can cost less per document. It should only replace the current model after it wins on a test built from your own data, and broad or fast-changing work often stays on a hosted API.

How do I do Gemini API cost optimization?

Start by logging input and output tokens for each call site, then trim prompts, cap output length and batch anything that can wait. Read Google's current pricing page for the caching and batch terms before you plan around them.

Why are my Vertex AI costs too high?

Split the bill by project, model and feature label before you touch the code. Vertex AI charges can include more than model tokens, so the Google Cloud pricing page is the place to confirm what applies to your setup.

Can I reduce Gemini API costs without changing the model?

Yes. Shorter inputs, output limits, prompt caching for repeated text, batch processing and removing retry loops all lower the bill while the model stays the same.