Gemini generateContent (metered tier)
POST /v1/metered/geminiGoogle's native generateContent wire on the metered tier. Send POST /v1/metered/gemini with the required field contents and pay quoted per request from $0.001 over x402 or MPP (there is no free tier). It returns a JSON object with candidates, usageMetadata and modelVersion.
Send Gemini's own request shape (contents, systemInstruction, generationConfig, function declarations) and get Gemini's own response shape (candidates, usageMetadata) back. Point a Google GenAI SDK at this gateway and pay per request with USDC, no account. Also answers the Google-shaped path /v1beta/models/<model>:generateContent.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contents | array | yes | Gemini turns: [{role, parts:[{text}|{inlineData}]}] |
systemInstruction | object | no | Optional system turn: {parts:[{text}]} |
generationConfig | object | no | maxOutputTokens, temperature, topP, stopSequences, responseMimeType, responseSchema |
tools | array | no | [{functionDeclarations:[{name, description, parameters}]}] |
model | string | no | Optional; the Google-shaped path carries it (/v1beta/models/<model>:generateContent) |
Example request
curl -i -X POST https://agent402.tools/v1/metered/gemini \
-H "Content-Type: application/json" \
-d '{"contents":[{"role":"user","parts":[{"text":"Summarize x402 in one sentence."}]}],"generationConfig":{"maxOutputTokens":256}}'
Without payment this returns HTTP 402 Payment Required with the exact price for v1-chat-metered-gemini; any x402 v2 or MPP client pays it and retries.
Example response
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "x402 is an HTTP-native way for agents to pay per request with USDC."
}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 14,
"candidatesTokenCount": 18,
"totalTokenCount": 32
},
"modelVersion": "google/gemini-3.5-flash-lite"
}
| Field | Type | Always present | In the example |
|---|---|---|---|
candidates | array of objects | yes | 1 item in the example |
usageMetadata | object | yes | 3 fields: promptTokenCount, candidatesTokenCount, totalTokenCount |
modelVersion | string | yes | google/gemini-3.5-flash-lite |
From an MCP client
catalog.call {
"slug": "v1-chat-metered-gemini",
"params": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize x402 in one sentence."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 256
}
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for v1-chat-metered-gemini; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
contentsis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce different wording.
- Priced per request: the 402 quotes this body, between $0.001 and $2.
- A
GETorHEADto /v1/metered/gemini returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB and a streamed response are not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/metered/gemini", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"contents": [
{
"role": "user",
"parts": [
{
"text": "Summarize x402 in one sentence."
}
]
}
],
"generationConfig": {
"maxOutputTokens": 256
}
}),
});
Related tools
Gemini generateContent (auto tier)
POST /v1/auto/geminiGoogle's native generateContent wire on the auto tier. Send Gemini's own request shape (contents, systemInstruction, gen…
Gemini generateContent (base tier)
POST /v1/geminiGoogle's native generateContent wire on the base tier. Send Gemini's own request shape (contents, systemInstruction, gen…
Gemini generateContent (nano tier)
POST /v1/nano/geminiGoogle's native generateContent wire on the nano tier. Send Gemini's own request shape (contents, systemInstruction, gen…
Gemini generateContent (premium tier)
POST /v1/premium/geminiGoogle's native generateContent wire on the premium tier. Send Gemini's own request shape (contents, systemInstruction, …
Gemini generateContent (pro tier)
POST /v1/pro/geminiGoogle's native generateContent wire on the pro tier. Send Gemini's own request shape (contents, systemInstruction, gene…
Text-to-speech (OpenAI-compatible)
POST /v1/audio/speechOpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url https://agent402.t…