The Gemini API in open-source AI tools: connecting Google's models to self-hosted apps in 2026
Two doors to the same models
Google sells Gemini to developers in two ways, and the choice affects setup, billing and data terms.
| Google AI Studio (Gemini API) | Vertex AI (Gemini Enterprise Agent Platform) | |
|---|---|---|
| Setup | API key from aistudio.google.com | Google Cloud project, service account, IAM |
| Free tier | Yes, rate-limited | Trial credits only |
| Billing | Linked Cloud billing account | Google Cloud invoice |
| Data use | Free tier may be used to improve products; paid tier not | Not used for training |
| Regions | Global | Global and regional endpoints |
| Best for | Individuals, prototypes, small teams | Companies on Google Cloud |
Both serve the same model families. Google has folded Vertex AI's generative services into Gemini Enterprise Agent Platform, and some older pieces, such as Vertex AI Extensions, are scheduled to shut down after November 26, 2026.
Which directory projects use it
| Project | How it connects |
|---|---|
| LibreChat | Native Google endpoint for AI Studio keys and Vertex service accounts |
| LobeChat | Built-in Gemini provider |
| Dify | Gemini and Vertex model provider plugins |
| LiteLLM | gemini/ and vertex_ai/ prefixes with cost tracking |
Models and prices
| Model | Status | Input per million | Output per million | Cached input |
|---|---|---|---|---|
| Gemini 4 Argon (to Nov 30, 2026) | GA, paid only | $2.00 | $10.00 | $0.10 |
| Gemini 4 Argon (from Dec 1, 2026) | GA, paid only | $4.00 | $20.00 | $0.20 |
| Gemini 3.5 Flash-Lite | Stable, free tier available | Low per-token rate | Low per-token rate | Discounted |
The introductory Argon price is worth noting in any budget: the same workload costs twice as much from December. Teams testing Argon in October should plan for the standard rate.
Gemini 3.5 Flash-Lite, updated in July 2026, accepts up to 1,048,576 input tokens and returns up to 65,536 output tokens. That long context window lets a self-hosted app send a whole contract set, codebase or book without building a retrieval pipeline first, though retrieval is still cheaper for repeated questions over large collections.
Long context in practice
Gemini models have led on context length for several years. Sending 500,000 tokens in one request is possible, but every request pays for every token, and latency grows with input size. Two habits keep costs sane:
- Use context caching. When many questions hit the same large document, cache it and pay the cached rate on later calls.
- Retrieve first, then read. For a library of thousands of documents, use a vector database such as Qdrant to find the ten most relevant, and send only those.
Setting it up
- For AI Studio: create a key at aistudio.google.com and link a billing account to move off the free tier.
- In LibreChat, set
GOOGLE_KEYin.env, or provide a service-account JSON for Vertex. - In LiteLLM, use
model: gemini/gemini-4-argonwithGEMINI_API_KEY, orvertex_ai/gemini-4-argonwith project and location set. - For apps that only speak OpenAI's format, Google offers an OpenAI-compatible endpoint at
https://generativelanguage.googleapis.com/v1beta/openai/.
Multimodal input and output
Gemini models accept text, images, audio, video and PDFs in one request. A self-hosted app can let users upload a recording of a meeting or a scanned form and ask questions about it directly. Google's media models, such as Veo for video and image models, are billed separately; note that the Veo 3.1 Lite preview was scheduled to shut down on October 22, 2026, with users pointed to newer models. Check model status before building on any preview.
What a month costs
At Argon's standard price from December 2026:
| Use | Monthly tokens | Rough cost |
|---|---|---|
| One heavy user | 3M in, 0.5M out | About $22 |
| Team of 20 | 40M in, 10M out | About $360 |
| Same team on Flash-Lite | 40M in, 10M out | A small fraction of that |
Many teams set Flash-Lite as the default and offer Argon for hard questions.
Data handling
The free tier is the main privacy trap. Google's terms allow free-tier prompts and responses to be used to improve its products, and human reviewers may read them. Paid-tier and Vertex AI traffic is excluded from training. If your self-hosted app is used for company data, make sure the key belongs to a billed project.
Grounding with Google Search
Gemini can ground answers in live Google Search results and return source links, a feature other providers lack in the same form. It is billed per grounded request on top of tokens, after a free daily allowance on some models. In a self-hosted chat app, this gives users web-backed answers without running a separate search tool such as SearXNG. Google's terms require showing the search suggestions it returns alongside grounded answers, so check that your app displays them.
Rate limits and quotas
AI Studio keys have per-model limits on requests per minute, tokens per minute and requests per day, set by your usage tier. Free-tier limits are low and change from time to time, so a self-hosted app shared with a team will hit them quickly. Paid tiers rise as cumulative spend grows. On Vertex AI, quotas are set per project and region and can be raised through the Cloud console, and Provisioned Throughput reserves capacity for steady production loads. When a request fails with a 429 error, a gateway such as LiteLLM can retry on another region or fall back to a different model.
Tool calling and structured output
Gemini supports function calling, JSON schema output and code execution in a sandbox, so it can drive agents in Dify, LibreChat and LangChain-based tools. Its function-calling format differs from OpenAI's, but LibreChat, LiteLLM and the OpenAI-compatible endpoint translate it. If an agent works on GPT and fails on Gemini, check how each tool's parameters are described: Gemini is stricter about some JSON schema features, and simplifying the schema often fixes the problem.
When to use something else
If your team prefers Claude for writing and code, see the Anthropic API. If EU residency is the priority, Mistral is simpler. If you need everything on your own hardware, run an open model through Ollama. Google's open Gemma models are another route to Google-quality small models offline.
Related: Google Cloud stack, OpenAI API stack, LiteLLM stack, ChatGPT alternatives, Stack index.
Frequently asked questions
Is the Gemini API free?
Partly. Google AI Studio offers a free tier with rate limits for several models, including Flash-class models. Gemini 4 Argon is paid only. On the free tier, Google may use prompts and responses to improve its products, so do not send confidential data through it.
How much does Gemini 4 Argon cost?
On the paid Gemini API tier, $2 per million input tokens and $10 per million output tokens through November 30, 2026, then $4 and $20 from December 1, 2026. Cached input costs $0.10 per million, rising to $0.20. Vertex AI regional prices can differ.
Should I use AI Studio or Vertex AI?
Use an AI Studio API key for personal projects and small teams; setup takes a minute. Use Vertex AI if your company already runs on Google Cloud, needs IAM roles, VPC controls, regional processing or a data processing agreement, or wants spend on the existing cloud bill.
Can I use Gemini in Open WebUI or LibreChat?
LibreChat has a native Google endpoint for both AI Studio keys and Vertex AI. LobeChat and Dify have Gemini providers. Open WebUI can connect through Google's OpenAI-compatible endpoint or through a LiteLLM proxy.
Does Google train on Gemini API data?
Google states that paid-tier and Vertex AI data is not used to improve its products. Free-tier data in AI Studio may be used for that purpose and reviewed by people. Check the current Gemini API terms before choosing a tier.
Which Gemini model should be the default in a self-hosted app?
A Flash-class model is the usual default for everyday chat because it is fast and cheap. Offer Gemini 4 Argon as a second option for hard reasoning, long documents and code, and watch the price change on December 1, 2026.