GeekHub Learn
Module
Lesson 5.44 of 8 in this module2 min read Module 5: Using AI APIs (OpenAI, Gemini, Anthropic)

The same call in Gemini and Claude

Multi-provider literacy is a 2026 must. Outages, price changes, and capability differences all favor engineers who can swap providers in an hour, not a month.

Three taxi apps in your city. The button is in slightly different places but the trip is the same. You should not become loyal to one because of the button.

All three APIs follow the same pattern with slight syntactic differences. The mental model is identical: messages in, response out, usage tracked.

Google Gemini:

import os
from google import genai

client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Explain RAG to a beginner in 2 sentences.",
)
print(response.text)

Anthropic Claude:

import os
from anthropic import Anthropic

client = Anthropic()
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=200,
    system="You are a tutor. Reply in 2 sentences.",
    messages=[{"role": "user", "content": "Explain RAG to a beginner."}],
)
print(message.content[0].text)

Key differences:

AspectOpenAIGeminiAnthropic
SDK nameopenaigoogle-genaianthropic
System messagerole in messagessystem_instructiontop-level system param
Response access.choices[0].message.content.text.content[0].text
Streamingyesyesyes
JSON Schemayesyesyes (tools)

Visualize it

A 3-column table comparing the three APIs across 6 dimensions (auth, system msg, streaming, JSON, tools, multimodal).

Try it now

Run the same prompt through all three providers. Note differences in tone, length, format.

Hands-on lab

Write a single Python file with ask_openai(q), ask_gemini(q), ask_claude(q). Run the same prompt through each. Save outputs for comparison.

Try it now

Which provider has the largest free tier as of today? (Check Google AI Studio.)

Common mistakes

  • Hard-coding provider-specific behavior throughout an app
  • Forgetting that Claude requires max_tokens
  • Comparing free-tier Gemini to paid GPT-4o and concluding quality differences

Debugging tip

When porting between providers, isolate the call in a thin adapter. Diffs become trivial.

Challenge

Build a "provider abstraction" layer with a single chat(provider, messages) function that works across all three.

Where this shows up

  • Multi-provider fallback for resilience
  • Price-aware routing
  • Vendor lock-in avoidance

From the field

The 2026 trend is provider-agnostic apps: route easy queries to cheap providers, hard ones to frontier. Knowing the SDKs natively (not via framework wrappers) makes you the engineer the team trusts.

Recap

Same shape, different buttons. Learn all three. It will take you one weekend and pay back forever.


Quick recall

3 prompts · think before you flip

Prompt 1 of 3

Where does Claude take the system instruction?

Quiz time

1 question · tap an answer to check it

  1. 1. Anthropic Claude's system instruction is sent as

Finished lesson 5.4?

Mark complete to update your module progress and unlock the streak.

Loading