Day 3 - Call 8 LLMs with the OpenAI-Compatible API: GPT, Claude, Gemini
Week 1 · Day 3 · Lecture 14. Lab file: 1_foundations/2_lab2.ipynb. With a question generated in the previous lecture — "What is one human virtue that can become a vice when optimized too aggressively, and why? Answer in no more than two sentences" — it's time to put it to eight different LLMs and compare the answers.
The trick: one API shape, many providers
Each provider has its own proprietary API, but nearly all of them — OpenAI, Anthropic (the last holdout, but they eventually added it), Google, DeepSeek, and even Ollama running locally on your own machine — also expose an OpenAI-compatible endpoint. That means you can talk to any of them using the exact same request format OpenAI uses, just by changing two things: the base_url and the api_key.
In practice this means you create a client using the OpenAI Python client library for every provider, not just OpenAI itself — you just override where it points:
anthropic = OpenAI(base_url=ANTHROPIC_BASE_URL, api_key=anthropic_api_key)
Confusing at first glance (a variable called anthropic that's really an instance of the OpenAI class) but powerful: the exact same .chat.completions.create(...) call now talks to Claude instead of GPT. Switch the base URL to localhost and the same code calls a local Ollama model instead. One shape, many destinations. (Guide 9 in the guides folder walks through this in detail.)
Setting up the run
- Base URLs for each provider are set once as constants, so the client-creation cells stay short and readable.
- Two lists track the run: competitors (which model answered) and answers (what it said) — kept in the same order so they line up.
- A small helper function wraps the repeated logic: append the competitor name, append the answer, print/display it — so each provider call is just a couple of lines.
- Small, fast models are used deliberately here rather than each provider's strongest flagship — the point of this exercise is exploring different agentic flows and providers, not benchmarking peak intelligence (that's covered elsewhere).
- Where supported, a
reasoning_effortparameter controls how much a model "thinks" before answering — set tononehere, thoughlow/medium/high/extra highare also options.
Six calls, six very different answers
All eight calls follow the identical pattern — client.chat.completions.create(model=..., messages=...), then read response.choices[0].message.content. Here's how the walkthrough plays out (your exact models and answers will differ — that's expected, since Day 3's question was itself LLM-generated and providers update their models constantly):
| Provider / model | Answer (paraphrased) |
|---|---|
| OpenAI — GPT nano | Discipline, over-optimized, becomes rigidity or obsessive control — prioritizing short-term efficiency over flexibility and compassion. |
| Anthropic — Claude Sonnet (via OpenAI-compatible endpoint) | Conscientiousness taken to an extreme collapses into perfectionism and rigidity, paralyzing decisions and damaging relationships. |
| Google — Gemini Flash Lite | Frugality over-optimized becomes stinginess — accumulation over utility, isolating the individual from the social value moderation protects. |
| DeepSeek — DeepSeek V4 | Discipline, over-optimized, becomes rigidity, suppressing creativity and adaptability (a succinct variant of the OpenAI answer). |
| Groq (inference provider) running an open-source model (GPT-OSS-120B) | Humility, over-optimized, becomes self-effacement — suppressing your own voice and necessary self-advocacy. |
| OpenRouter, routing to Kimi K2.6 (Moonshot AI) | Honesty pursued to an extreme becomes cruelty masquerading as integrity — truth without tact erodes the trust it claims to serve. |
A few things worth noticing in this run: Groq is an inference provider, not a model — the actual model answering was GPT-OSS-120B (OpenAI's open-source model, released as an answer to DeepSeek's open-source push), just served extremely fast on Groq's hardware. And OpenRouter was used here to reach Kimi K2.6 from Chinese startup Moonshot AI — at the time of recording, considered the strongest openly available model, ahead of the more hyped DeepSeek (check Artificial Analysis for the current leaderboard). Kimi also visibly took much longer to answer (37 seconds of reasoning) — a reminder that "smartest" and "fastest" are frequently in tension.
Notice too how much the different models converged on similar shapes of answer (discipline/conscientiousness → rigidity shows up three separate times) while still phrasing it distinctly — a nice illustration of both the shared "reasonable answer" space and each model's own voice.
What you should now understand
- Most LLM providers expose an OpenAI-compatible endpoint, so one client shape (the
OpenAIPython class) can talk to OpenAI, Anthropic, Google, DeepSeek, Ollama, and more — you only changebase_urlandapi_key. - Tracking parallel
competitors/answerslists, plus a small helper function, keeps a multi-provider comparison loop readable. - Groq and OpenRouter are not model providers — they're an inference provider and a router, respectively, serving other companies' open-source models.
reasoning_effort(none/low/medium/high/extra high) controls how much a supporting model "thinks" before responding.- Different models frequently converge on the same underlying idea while expressing it in noticeably different voices — worth watching for as you compare answers yourself.
Resource links
- Artificial Analysis — current open-source and closed model rankings
- OpenRouter — one key, routed to many providers including Kimi K2.6
- Groq — fast inference for open-source models like GPT-OSS-120B
- Course resources page (Guide 9 covers the OpenAI-compatible endpoint pattern in full)
- This lecture on Udemy
Next
With eight answers collected, the next step is judging them against each other — an early taste of the "LLM as a judge" pattern covered later in the week.