Gemini API (native)
Gemini models also speak Google's own GenerateContent API, the format the Google GenAI and Vertex AI
SDKs send. The gateway serves it on Google's own paths, both the Google AI (Gemini Developer API) shape
and the Vertex AI shape, so the official SDKs work unchanged: point their base URL at the gateway
and use your LLM API key.
Requests and responses keep Google's wire format. The gateway authenticates the call, routes it to a
Google provider that serves the model (Google AI Studio or Vertex AI, with fallback between them),
sends the model's upstream name, and relays the body both ways — tools, generationConfig,
thinkingConfig, safety settings and anything Google adds later keep working.
INFO
This API serves Gemini models only. Any other model — gpt-5.6, a Claude model — gets a 404 NOT_FOUND here and is never sent upstream; use Chat Completions for
those. Gemini Live uses its own WebSocket endpoint — see Gemini Live.
Use the Google GenAI SDK
Python (google-genai):
from google import genai
from google.genai import types
client = genai.Client(
api_key=LLM_API_KEY,
http_options=types.HttpOptions(base_url="https://api.llmapi.ai"),
)
response = client.models.generate_content(model="gemini-2.5-flash", contents="Hello!")
print(response.text)
for chunk in client.models.generate_content_stream(model="gemini-2.5-flash", contents="Hello!"):
print(chunk.text, end="")
print(client.models.count_tokens(model="gemini-2.5-flash", contents="Hello!").total_tokens)
JavaScript / TypeScript (@google/genai):
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: LLM_API_KEY,
httpOptions: { baseUrl: "https://api.llmapi.ai" },
});
const response = await ai.models.generateContent({ model: "gemini-2.5-flash", contents: "Hello!" });
console.log(response.text);
Vertex AI mode
The GenAI SDK in Vertex AI mode works the same way. With an API key (Vertex express mode):
client = genai.Client(
vertexai=True,
api_key=LLM_API_KEY,
http_options=types.HttpOptions(base_url="https://api.llmapi.ai"),
)
Or keep your project and location and pass the LLM API key as the credential. The project and location
in the path are accepted and ignored:
from google.oauth2.credentials import Credentials
client = genai.Client(
vertexai=True,
project="my-project",
location="us-central1",
credentials=Credentials(token=LLM_API_KEY),
http_options=types.HttpOptions(base_url="https://api.llmapi.ai"),
)
Use the Vertex AI SDK
The vertexai package (google-cloud-aiplatform) works over REST:
import vertexai
from google.oauth2.credentials import Credentials
from vertexai.generative_models import GenerativeModel
vertexai.init(
project="my-project",
location="us-central1",
credentials=Credentials(token=LLM_API_KEY),
api_endpoint="https://api.llmapi.ai",
api_transport="rest",
)
model = GenerativeModel("gemini-2.5-flash")
print(model.generate_content("Hello!").text)
for chunk in model.generate_content("Hello!", stream=True):
print(chunk.text, end="")
api_transport="rest" is required: the gateway does not serve gRPC.
Call it without an SDK
curl https://api.llmapi.ai/v1beta/models/gemini-2.5-flash:generateContent \
-H "x-goog-api-key: $LLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents":[{"role":"user","parts":[{"text":"Hello!"}]}]}'
Paths
| Shape |
Path |
| Google AI |
/v1beta/models/{model}:{method} |
| Vertex AI |
/v1/projects/{project}/locations/{location}/publishers/google/models/{model}:{method} |
| Vertex AI (GenAI SDK) |
/v1beta1/projects/{project}/locations/{location}/publishers/google/models/{model}:{method} |
| Vertex AI express mode |
/v1/publishers/google/models/{model}:{method} and the same under /v1beta1 |
Google AI's stable v1 shape (/v1/models/{model}:{method}, what the GenAI SDK sends with
api_version="v1") is not served, because it collides with the gateway's own /v1/models; keep the
SDK's default v1beta. These paths are served by the global endpoint https://api.llmapi.ai only, not
by the regional ones.
{method} is one of:
generateContent — one response.
streamGenerateContent — a stream: server-sent events with ?alt=sse (what the GenAI SDKs ask for),
otherwise a streamed JSON array, as Google sends by default.
countTokens — the prompt's token count. Either Google AI's body (contents or
generateContentRequest) or Vertex AI's (contents, systemInstruction, tools) is accepted
on every path.
GET on a model collection lists the Gemini models (models on Google AI paths, publisherModels on
Vertex AI paths), and GET .../{model} describes one. Listings need no key, like
/v1/models.
Authentication
| Form |
Used by |
x-goog-api-key: $LLM_API_KEY |
GenAI SDKs, server-side clients |
?key=$LLM_API_KEY |
Browsers and clients without headers |
Authorization: Bearer $KEY |
Vertex AI SDK, any client with headers |
WARNING
A key in a query string is visible to anything that logs URLs. Use it only where a header is
impossible.
Routing and limits
Calls run through the same checks as /v1/chat/completions: the API key's IAM rules and the
organization's model and provider blocks, credit balance, spend limits, rate limits (counted against
the model in the path) and subscription plans. A Gemini model served by both Google AI Studio and
Vertex AI falls back from one to the other when a provider fails, unless fallback is off for your
organization or the request sends X-No-Fallback: true.
- Guardrails are not evaluated on this API. A project with guardrails that would apply to Chat
Completions gets a
400 here — use Chat Completions for that project.
- Grounding with Google Search (
googleSearch, googleSearchRetrieval) is billed by Google per
search, so on LLM API credit it is available on models whose mapping enables native web search, and
each distinct search the response reports is billed at the model's web-search price.
- Function calling, code execution and URL context bill as ordinary tokens and work everywhere.
Any other tool — Google Maps, enterprise web search, file search, or a tool Google adds later — needs
your own Google API key (a project in API-keys mode); on LLM API credit it gets a
400.
- A request served by Google AI Studio drops Vertex AI's
labels, which Google AI rejects. A
modelArmorConfig is refused with a 400: its templates live in your Google project.
- References to your own Google resources —
cachedContent, Files API URIs, gs:// URIs — point at
your Google project, which the gateway's keys cannot read.
Billing
Usage bills from the usageMetadata Google reports, exactly as Gemini on Chat Completions:
- Input tokens at the input price, including the
toolUsePromptTokenCount that URL context, code
execution and search add; cachedContentTokenCount at the cached-input price.
- Output tokens (
candidatesTokenCount) at the output price, and thinking tokens
(thoughtsTokenCount) at the reasoning price, or the output price when the model has none.
- Audio input and image output tokens at their own prices where the model sets them.
countTokens is free.
Responses carry no extra cost fields, so the body stays exactly what Google sends. Each
generateContent and streamGenerateContent call appears in your logs and analytics with its tokens
and cost; countTokens calls are neither billed nor logged.
Errors
Errors use Google's envelope, so the SDKs raise them as their own API errors:
{
"error": {
"code": 402,
"message": "Insufficient credits. Your organization's credit balance is exhausted. Please add credits to continue using the API.",
"status": "FAILED_PRECONDITION",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "insufficient_credits",
"domain": "llmapi.ai"
}
]
}
}
The reason is the gateway's error code, the same one the other endpoints return in error.code;
branch on it rather than on the message. Errors Google returns for the request itself
(400 INVALID_ARGUMENT and the like) keep Google's message.
| Status |
status |
Meaning |
| 400 |
INVALID_ARGUMENT |
Invalid request, a tool or field not available on credit, guardrails |
| 401 |
UNAUTHENTICATED |
Missing or invalid API key |
| 402 |
FAILED_PRECONDITION |
No credit left (insufficient_credits), or bonus credits that do not cover this provider (bonus_credits_not_applicable) |
| 403 |
PERMISSION_DENIED |
The key's rules or the organization block the model |
| 404 |
NOT_FOUND |
Not a Gemini model, unknown model, or unknown method |
| 429 |
RESOURCE_EXHAUSTED |
Rate limit (rate_limit_exceeded; Retry-After says when to retry) or a spend or subscription limit, which retrying will not clear |
| 500 |
INTERNAL |
The gateway failed |
| 502 |
UNAVAILABLE |
The Google provider could not be reached or its answer could not be read |
| 503 |
UNAVAILABLE |
No Google provider could serve the request, or guardrails are temporarily unavailable; retry later |
API operation: POST /v1beta/models/{model}:generateContent