Provider setup
Before any of the agent code can run, it needs to know where to send a request, which key authorizes it, and which model to ask for. This page gets those three values in place.
Your API key is a credential
Treat it the way you'd treat a password. Never paste it into a JavaScript file, never commit it, never post it in a Discord message asking for help. Anyone holding your key can spend your credit.
That rule is also why the course keeps every API call on a server instead of in the browser. Browser code is visible to anyone who opens their browser's developer tools, so a key used there is a key you've given away.
Check what you already have
If you've taken Intro to AI Engineering, these variables may still be saved in your Scrimba account.
Open Settings in the Scrimba editor, then select Edit Environment. You're looking for three entries named exactly AI_URL, AI_KEY, and AI_MODEL.
If all three are there and point at a provider you still have credit with, you're most likely ready. Jump ahead to recommended models and confirm the model in AI_MODEL supports tool calling, since that requirement is stricter in this course than it was in the last one.
If any are missing, or you want to switch providers, keep reading.
Checking takes ten seconds and can save you creating a second account you don't need!
Which provider
OpenAI is the default used by this course. Its API is the one the Responses API originates from, and using it requires API credit. Costs depend on the model, request size, and how much you experiment, so check the current pricing before adding an amount you are comfortable using.
OpenRouter is the alternative if you can't or don't want to use OpenAI. It's a single API that routes to many providers, including free-tier models, and it speaks the same OpenAI-compatible shape, so the course code doesn't change.
Either way the setup is the same shape: create an account, generate a key, then store the provider's URL, your key, and a model ID.
Pick OpenRouter if paying OpenAI directly is awkward where you are, or if you want to try a free model first.
Setting up OpenAI
Head to the OpenAI developer platform and sign in or create an account.
ChatGPT Plus is not API credit
The developer platform is billed separately from a ChatGPT subscription. Having ChatGPT Plus does not give your API account any credit, and this catches nearly everyone once.
Open Billing in the platform settings and add credit if your account has none. Check the current model pricing and set a budget that suits your own usage.
Now open API keys in the platform settings and select Create new secret key. Give it a name that will still mean something to you in three months. When the key is created, copy it immediately, because the full value is shown exactly once and cannot be retrieved afterwards.
Back in Scrimba, open Edit Environment and set:
AI_URL=https://api.openai.com/v1
AI_KEY=your-api-key-here
AI_MODEL=gpt-5.4-nanoSee recommended models if you want something other than the default. Save the environment variables once all three are in place.
Set a billing budget while you are in there. It takes a minute and means a runaway loop can never turn into a surprise!
Setting up OpenRouter
Create an OpenRouter account, open the API Keys page, and create a key.
OpenRouter does offer free models, and they're useful for learning. Be aware of two things before you rely on one.
Free endpoints are not guaranteed to be available, and their behavior can differ from one run to the next, which makes it hard to tell whether an odd result came from your code or from the model. Free endpoints may also route your requests to providers with different data policies, so open the Privacy settings and make a deliberate decision before enabling them.
If you want consistent results, the same advice applies here as with OpenAI: load a small amount of credit and pick a lightweight paid model.
In Scrimba, set:
AI_URL=https://openrouter.ai/api/v1
AI_KEY=your-api-key-here
AI_MODEL=mistralai/ministral-3b-2512Save the environment variables.
Watch the model ID format: it includes the provider in front, so it is mistralai/ministral-3b-2512 and not the short name on its own. That prefix trips people up constantly!
The three values move together
The most common setup failure is a mismatched set instead of a single wrong value. A valid OpenAI key against OpenRouter's URL fails. A valid OpenRouter setup with an OpenAI-only model ID fails. Both produce authentication or model-not-found errors that read like something is broken in the course code.
So whenever you change providers, change AI_URL, AI_KEY, and AI_MODEL as one set, and save them together.
Running the code on your own machine?
Scrimba stores these as account-level environment variables, which is why there's no .env file in the browser project. On your own machine you'll put the same three values into a .env file instead. Running the code locally covers that.
The error messages are not much help here, because they describe what went wrong at the provider, so they read as though the course code is broken. It usually isn't!
Where this goes next
Recommended models covers what makes a model suitable for agent work and which ones have been tested against this course. If you'd rather see how the request itself is put together, Chat Completions and Responses compares the two API shapes.

