Built from the official docs: Gemini 4 Carbon - API Pricing & Benchmarks · openrouter.ai · Getting started | Gemini API | Google AI for Developers · checked 20 November 2026
Through OpenRouter
Get an OpenRouter API key
Sign up on OpenRouter and create an API key from your dashboard. You'll pass it as a Bearer token on every request.
Export your key
Store the key in an environment variable so the examples below can read it.
export OPENROUTER_API_KEY="<your-openrouter-key>"Call the model with curl
Send a POST to the OpenRouter responses endpoint. Use the model slug google/gemini-4-carbon and put your prompt in the input field.
curl https://openrouter.ai/api/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -d '{ "model": "google/gemini-4-carbon", "input": "What is the meaning of life?" }'Or call it from Python
OpenRouter's API is OpenAI-compatible, so you can point the OpenAI SDK at OpenRouter by setting the base URL and your key.
from openai import OpenAI client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key="<your-openrouter-key>", ) response = client.responses.create( model="google/gemini-4-carbon", input="What is the meaning of life?" ) print(response.output_text)
Direct from Google
Get a Gemini API key
Create a key on the Google AI Studio API keys page; AI Studio automatically creates a project and key for new users.
Set your key as an environment variable
The Gemini SDKs and REST calls read your key from this variable.
export GEMINI_API_KEY="<your-gemini-api-key>"Install the SDK (Python)
Install the official Google GenAI SDK with pip.
pip install -U google-genaiMake your first call
Initialize the client and create an interaction. Set model to the Gemini model id you want to use.
from google import genai client = genai.Client() interaction = client.interactions.create( model="<gemini-model-id>", input="Explain how AI works in a few words" ) print(interaction.output_text)
Check it worked
You get a completed response with text in it — for curl, the JSON shows "status": "completed" with an output_text; for the SDK calls, response.output_text / interaction.output_text prints a non-empty answer.