SarvamStack

    Week 1–2

    APIs & Ollama

    One interface, many providers. Commercial APIs, free tiers, and local Ollama — all with the same patterns.

    Pause & reflect

    Before you read on, answer this in your head — or on paper:

    You've run Ollama locally. Now you want to call GPT-4 or Claude from your app.

    What do you think would change in your code? Same prompt, same response format — but the request goes somewhere else. What stays the same? What must change?

    Take about 30 seconds. No skipping — thinking first makes the next part stick.

    Most LLM APIs follow the same shape: messages (system, user, assistant), model name, temperature, and max_tokens. Ollama exposes the same pattern locally. Once you can call one, you can call any. Use LiteLLM for a unified interface. OpenRouter provides one API for many providers, including free tiers.

    Before you continue: When would you use Ollama vs. an API? Trade-offs: cost, latency, privacy, model quality.Pause 25s. Then read on.

    Provider comparison

    ProviderBest forCheapest model
    OllamaLocal, free, no keysFree (Llama 3.2, Mistral, etc.)
    OpenAIGPT-4, frontier qualitygpt-4.1-nano
    AnthropicClaude, long contextclaude-3-haiku
    OpenRouterOne API, many modelsFree tiers (Llama, Mistral)
    Google GeminiMultimodal, free tiergemini-1.5-flash
    DeepSeekLow cost, strong codingdeepseek-chat

    Test your understanding

    Don't reveal yet. Think for ~30 seconds first — what would you try?

    You want to switch from Ollama (local) to OpenAI (cloud) without rewriting your app. What's the simplest approach?

    Check your understanding

    ?

    How can you minimise API cost during the LLM course?

    ?

    What is OpenRouter useful for?