Gemini developer API calls through MCP tools

developer2026-11-06

On this page

The Gemini developer API is Google's HTTP interface for sending prompts to Gemini models. It returns the results as JSON. To let an AI agent use it, expose those calls as MCP tools. The agent then requests a Gemini answer the same way it requests any other tool result.

What the Gemini developer API provides

The Gemini developer API gives your code direct access to Gemini models. It accepts a prompt, optional instructions, and generation settings, then returns generated content as JSON. Google hosts the models, so your code sends HTTPS requests and does not run a model locally.

Google documents endpoints, request fields, and model names at https://ai.google.dev/gemini-api/docs. Check that reference before you write code, because model names and fields change between releases.

The API also accepts multimodal input. A request can carry images, audio, or documents next to the text. Confirm which input types a given model accepts in the reference before you design around them.

Authenticate and send a first request

Create an API key in Google AI Studio. Store the key in an environment variable. Keep the key out of client-side code and out of public repositories. Send each request to the generateContent method. Pass the key in a request header.

A minimal request names a model and carries one text part. The response returns candidate text inside a JSON object. Read the text from the first candidate, and check the finish reason before you trust the output.

Keep the first call small. A single prompt with a short expected reply shows whether the key, the model name, and your parser all work. Add tools, system instructions, and long context after that first call succeeds.

Request fields that matter

Most requests need three parts: the model name, the contents, and the generation settings. The contents carry the prompt and any earlier turns. The generation settings control output length and sampling.

Set a maximum output token count on every call. Without that limit, one request can return far more text than the agent needs. Lower the temperature when the task needs repeatable answers, such as extraction or classification.

Give an agent Gemini calls as MCP tools

An agent does not call HTTP endpoints on its own. It calls tools that an MCP server exposes. Wrap the Gemini call in a tool with a name, a plain description, and a JSON input schema. The model then decides when to call the tool and reads the JSON result.

Write the schema narrowly. Accept a prompt string, an optional model name, and an optional output limit. Reject other fields. A narrow schema keeps the agent from sending settings your team has not reviewed.

Build the tool around three decisions:

  • Name the tool after the task, for example summarise_document, rather than gemini_call.
  • Limit the input schema to the fields the task needs.
  • Return errors as tool results with a clear message the agent can act on.

An agent can retry a rate limit error. It cannot act on a silent empty reply, so never return an empty success.

Route Gemini calls through an MCP gateway

APIbase provides an MCP gateway with a large and growing catalog of tools across many categories. An agent reaches those tools through one connection, so a Gemini tool can sit beside tools from other categories. Check the catalog for a current Gemini tool before you build one.

A gateway helps when one agent uses several APIs. Each provider has its own key, rate rules, and error format. The gateway hides those differences behind one tool interface.

Call the API directly when the agent needs only one model. A direct SDK call has fewer moving parts and fewer dependencies to maintain.

Test the tool before an agent uses it

Run the tool against a fixed set of prompts before you connect it to an agent. Record the input, the output, and the latency for each prompt. A fixed set exposes regressions when a model version changes.

Check the output format as well as the content. If the agent expects JSON, parse the reply inside the tool and return an error when parsing fails. Do not pass malformed text to the next step.

Test the failure paths too. Send an invalid key, an oversized prompt, and a request made after the quota runs out. Each case should return a clear error message to the agent.

Pricing and limits

Gemini API prices depend on the model, the input size, and the output size. Google publishes current rates at https://ai.google.dev/pricing. This page does not repeat those rates, because they change.

APIbase lists per-tool prices in the catalog. Those prices run from 0 USD to 29.99 USD, and the exact figure depends on the tool you call.

Quota limits also change. Check your project's quota settings in Google AI Studio before you run a load test. When a call hits a rate limit, the API returns HTTP 429, so your tool should back off and retry.

Common mistakes to avoid

Teams often hardcode the model name. Models retire over time, so read the name from configuration instead.

Teams also forward raw user text to the model without limits. Set a maximum output length and a timeout on every call. A long reply can stall an agent loop.

Finally, teams log full responses. A response can echo sensitive input the user sent, so redact fields before you write logs.

Live pricing — developer

Price per call, developer tools Horizontal bar chart of the price per call and the cache-hit price, in US dollars, for 12 developer tools. The same values are in the table below the chart. Price per call Cache-hit price $0.0 $0.0005 $0.001 Usage Time SeriesUsage Time Series $0.0 $0.0 Per-Tool Usage BreakdownPer-Tool Usage Breakdown $0.0 $0.0 Usage SummaryUsage Summary $0.0 $0.0 Discover ToolsDiscover Tools $0.0 $0.0 Batch Tool CallsBatch Tool Calls $0.0 $0.0 Tool Quality MetricsTool Quality Metrics $0.0 $0.0 Tool Quality RankingsTool Quality Rankings $0.0 $0.0 List Programming LanguagesList Programming Languages $0.001 $0.0001 Check CVE ID Reservation Stat…Check CVE ID Reservation Status $0.001 $0.0001 Security Advisories (deps.dev)Security Advisories (deps.dev) $0.001 $0.0001 Dependency Tree (deps.dev)Dependency Tree (deps.dev) $0.001 $0.0001 Package Info (deps.dev)Package Info (deps.dev) $0.001 $0.0001 US dollars per call
Price per call for developer tools, cheapest first.

Data source: live tool catalog snapshot, fetched 2026-11-06.

Chart data as a table
ToolPrice per callCache-hit price
Usage Time Series$0.0$0.0
Per-Tool Usage Breakdown$0.0$0.0
Usage Summary$0.0$0.0
Discover Tools$0.0$0.0
Batch Tool Calls$0.0$0.0
Tool Quality Metrics$0.0$0.0
Tool Quality Rankings$0.0$0.0
List Programming Languages$0.001$0.0001
Check CVE ID Reservation Status$0.001$0.0001
Security Advisories (deps.dev)$0.001$0.0001
Dependency Tree (deps.dev)$0.001$0.0001
Package Info (deps.dev)$0.001$0.0001
ToolProviderPrice/callCache-hit
Usage Time Seriesaccount$0$0
Per-Tool Usage Breakdownaccount$0$0
Usage Summaryaccount$0$0
Discover Toolsapibase$0$0
Batch Tool Callsplatform$0$0
Tool Quality Metricsplatform$0$0
Tool Quality Rankingsplatform$0$0
List Programming Languagesjudge0$0.001$0.0001
Check CVE ID Reservation Statuscve-mitre$0.001$0.0001
Security Advisories (deps.dev)depsdev$0.001$0.0001
Dependency Tree (deps.dev)depsdev$0.001$0.0001
Package Info (deps.dev)depsdev$0.001$0.0001

Connect via MCP

How a tool call worksAn AI agent sends a tool call to the APIbase gateway. The gateway checks payment, calls the provider API, and returns the JSON result to the agent.Your agentAPIbase gatewayProvider API1. tool call2. paid call3. JSON result flows back to the agent
Diagram: the path of one tool call.

Data source: gateway design, no measured values.

$ curl -X POST https://apibase.pro/api/v1/tools/account.timeseries/call \
  -H "Content-Type: application/json" -d '{"params": {}}'

FAQ

Is the Gemini developer API free to use?

Google's pricing page at https://ai.google.dev/pricing lists the rate for each model and whether a free tier applies. Rates change, so check the page before you plan usage.

Does an agent need an MCP server to use the Gemini API?

An agent calls tools through MCP, so something must expose the Gemini call as a tool. You can build a small MCP server yourself, or you can use an MCP gateway that already provides the tool.

How does the Gemini developer API authenticate requests?

It uses an API key that you send in a request header. Keep the key on the server side and load it from an environment variable.

What should an agent do when a Gemini call fails?

The agent should read the error code, retry rate limit errors with backoff, and report other errors to the user instead of guessing at an answer.

Where do I find current Gemini model names?

Google's Gemini API reference at https://ai.google.dev/gemini-api/docs lists the current model names and their supported input types.

  1. STEP 1/2 Connect your MCP client
  2. STEP 2/2 Browse the full catalog

Written with AI assistance from APIbase's published documentation and public data; checked automatically against them. Corrections: https://apibase.pro/

Published: 2026-11-06Source: live apibase.pro catalog snapshot