Learn AI
    navigate Enter open Esc close Open with K or /

    4 min

    LLM APIs in 4 minutes

    OpenAI, Anthropic, Google — same shape, three vendors.

    Every coding assistant, every agent, every custom tool you'd build talks to an LLM API. Three big vendors, plus aggregators. Same shape.

    1

    Get a key

    One env var per provider. OPENAI_API_KEY · ANTHROPIC_API_KEY · GEMINI_API_KEY

    2

    Pick a model

    Each vendor has fast / smart / cheap tiers. Pick by your task.

    3

    Send a message

    One HTTP call → reply. That's the whole API.

    The same call, three vendors

    OpenAI

    from openai import OpenAI
    client = OpenAI()  # reads OPENAI_API_KEY
    
    reply = client.chat.completions.create(
        model="gpt-5",
        messages=[{"role": "user", "content": "Say hello."}],
    )
    print(reply.choices[0].message.content)

    Anthropic

    from anthropic import Anthropic
    client = Anthropic()  # reads ANTHROPIC_API_KEY
    
    reply = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=256,
        messages=[{"role": "user", "content": "Say hello."}],
    )
    print(reply.content[0].text)

    Google Gemini

    from google import genai
    client = genai.Client()  # reads GEMINI_API_KEY
    
    reply = client.models.generate_content(
        model="gemini-3-pro",
        contents="Say hello.",
    )
    print(reply.text)

    Or: one key, any model (OpenRouter)

    OpenRouter proxies hundreds of models from every vendor behind a single OpenAI-compatible API. Useful when you want to A/B-test models, or when you don't want vendor lock-in.

    from openai import OpenAI  # OpenAI-compatible
    client = OpenAI(base_url="https://openrouter.ai/api/v1",
                    api_key="sk-or-…")
    
    reply = client.chat.completions.create(
        model="anthropic/claude-sonnet-4-6",   # any model from any provider
        messages=[{"role": "user", "content": "Say hello."}],
    )

    Where to get keys

    VendorConsoleEnv var
    OpenAIplatform.openai.comOPENAI_API_KEY
    Anthropicconsole.anthropic.comANTHROPIC_API_KEY
    Google Geminiaistudio.google.comGEMINI_API_KEY
    Mistralconsole.mistral.aiMISTRAL_API_KEY
    DeepSeekplatform.deepseek.comDEEPSEEK_API_KEY
    OpenRouter (aggregator)openrouter.aiOPENROUTER_API_KEY
    Prompt caching. When a tool sends the same context (system prompt, project files, history) repeatedly, most vendors can cache the input — drastically cheaper and faster. Good tools enable it automatically.