Both APIs are non-OpenAI, so this is an involved remap. You convert Gemini’s contents/parts into Claude’s messages, move the system instruction to Claude’s top-level system, and make max_tokens explicit (Claude requires it).
API concept mapping
| Concept | Gemini (native) | Anthropic |
|---|---|---|
| SDK | google-genai | anthropic |
| Auth | GEMINI_API_KEY | x-api-key + anthropic-version |
| Call | models.generate_content | messages.create |
| Turns | contents[] (user/model) | messages[] (user/assistant) |
| System prompt | config.system_instruction | top-level system param |
| Max output | config.max_output_tokens | max_tokens (required) |
| Response text | response.text | content[0].text |
| Tools | config.tools (declarations) | tools + tool_use blocks |
Before / after
from google import genai
from google.genai import types
client = genai.Client()
resp = client.models.generate_content(
model="gemini-2.5-flash",
contents="Explain rate limits in one line.",
config=types.GenerateContentConfig(system_instruction="You are concise.", max_output_tokens=1024),
)
print(resp.text) import anthropic
client = anthropic.Anthropic()
resp = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024, # required on Anthropic
system="You are concise.", # was config.system_instruction
messages=[{"role": "user", "content": "Explain rate limits in one line."}],
)
print(resp.content[0].text) Watch for these
- Role rename: Gemini
model→ Anthropicassistant. - System instruction → top-level
system;max_output_tokens→ requiredmax_tokens. - Response path becomes
content[0].text. - Tools: Gemini function declarations → Claude
toolswithinput_schema; results come back astool_useblocks and go in astool_resultblocks in a user message. - Handle
529 Overloaded(Anthropic’s capacity signal) in addition to429. - Re-tune prompts and re-run evals.
What to do next
- Convert
contents→ Claudemessages(renamemodel→assistant). - Move the system instruction to top-level
system; set a requiredmax_tokens. - Port tool declarations to Claude’s
tools/input_schemaand thetool_resultround-trip. - Re-price with the cost calculator; reverse route is Anthropic → Gemini. The Claude target mechanics match OpenAI → Anthropic.
Frequently asked questions
What makes Gemini → Anthropic involved?
Neither side is OpenAI-shaped, so there's no compatibility shortcut for the whole flow. You remap Gemini's
contents/parts to Claude's messages, move the system instruction to the top-level system, and add a required max_tokens.How do roles and the response differ?
Gemini's assistant role is
model (becomes Anthropic assistant), and you read content[0].text on Claude instead of response.text.Anything new to handle on Claude?
Yes — Claude can return
529 Overloaded when its API is at capacity, separate from 429 rate limits. Add backoff for both, and remember max_tokens is mandatory.