Agent402 / tools / v1-chat-metered-gemini

Gemini generateContent (metered tier)

$0.001 per call · USDC via x402 · POST /v1/metered/gemini

Google's native generateContent wire on the metered tier. 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.

TRY IN PLAYGROUND →

Input

FieldTypeDescription
contents *arrayGemini turns: [{role, parts:[{text}|{inlineData}]}]
systemInstructionobjectOptional system turn: {parts:[{text}]}
generationConfigobjectmaxOutputTokens, temperature, topP, stopSequences, responseMimeType, responseSchema
toolsarray[{functionDeclarations:[{name, description, parameters}]}]
modelstringOptional; the Google-shaped path carries it (/v1beta/models/<model>:generateContent)

Example output

{
  "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-2.5-flash"
}

Try it - see the 402 challenge (free)

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}}'

The response is HTTP 402 Payment Required with exact payment requirements. Any x402 v2 client pays automatically and retries:

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";
import { metaTitle, metaDescription } from "./seo-meta.js";

const client = new x402Client();
client.setSpendControls?.(false); // @x402/core 2.23+ refuses anything over $1 or off the pegged-asset list by default; keep your own ceiling in code instead
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
    }
  }),
});
Wallet-only. This tool reaches the network/browser/storage, so it is paid in USDC via x402 (no proof-of-work tier).

Related tools

Chat completions - metered (pay what the call costs)

$0.001 · POST /v1/metered/chat/completions

OpenAI-compatible chat completions billed per request from what the call costs: the 402 quotes exact-BPE input plus your…

try in playground →

Chat completions - nano tier

$0.003 · POST /v1/nano/chat/completions

OpenAI-compatible chat completions, nano tier: gpt-5.6-luna, gpt-5-nano, gemini flash-lite, small llama/ministral/qwen, …

try in playground →

Chat completions - auto tier (eval-ranked routing)

$0.01 · POST /v1/auto/chat/completions

OpenAI-compatible chat completions with server-side model choice: omit "model" (or send "auto") and the gateway routes t…

try in playground →