API keys and calling an LLM API

Tuesday, 11/03 · Week 10

Mini Project 3: API-Powered App (repo URL) Due Wednesday, 11/04 Checkpoint 5 Due Sunday, 11/08 Mini Project 3: API-Powered App Due Sunday, 11/08

Post-Class Notes

TL;DR#

Today we looked at where an API key can live, moved one behind a function on Vercel, and used the same pattern to deploy a page that calls a model. The habit worth keeping: a secret key goes in Vercel's settings and your function reads it from there, so it is in no file in your repo and never reaches the browser.

Before next class#

Checkpoint 5 is due Sunday 11/08.

  1. Mini Project 3. Your repo URL is due on Canvas Wednesday 11/04. The project is due Sunday 11/08, deployed and working, and the showcase and Walkthrough 3 will be in class on Tuesday 11/10. Check your API before you build on it.
  2. ai-chat.html and api/ask.js in your oim3690 repo, working on your vercel.app link before class on Thursday 11/05. Both are on Checkpoint 5, and we will keep building on them in class. The steps are the Ask AI Your Turn in Calling an LLM API.

On Thursday 11/05 we will read ask.js together, see how the call to the model works, and improve ai-chat.html.

Where a key can go#

Treat a secret key like a password. Before you paste code into an AI agent, take the key out.

  • Written into a file you push: public. Your repos for this course are public, and bots scan GitHub for keys.
  • In a config.js listed in .gitignore: the key stays off GitHub, so the page works only on your own computer. If you deploy that file, every visitor can read it in the Sources tab.
  • In an environment variable on Vercel: your function reads it as process.env.FINNHUB_API_KEY, your page calls your function, and your function calls the API. Open Network on the deployed page and look for the key: it is not there.

Not every key is secret. The table in Kinds of API Access lists what someone else could do with each kind. A key that can spend your money or read your data must never go in browser code.

Check your API from your own site#

Run the Console check for Mini Project 3 from your own oim3690 site, as the slide shows. In class I told you that any page would do, but another site's security rules can refuse the request, which makes a working API look broken.

CORS is a check the browser makes. When your page fetches from another site, the browser looks for an access-control-allow-origin header in the answer. To see it, open Network, click the request, and read Response Headers.

What .gitignore matches#
  • config.js matches a file with that name in any folder, so it covers js/config.js too.
  • /config.js matches only the one in the root folder.

In class I told you that a bare file name misses a file in js/, and a slide said the same. That was wrong, and the slide is fixed. To check a file, run git check-ignore -v js/config.js: it prints the rule that matches, or nothing if the file is not ignored.

Read the level before the field#

data is the whole response. On the towns endpoint, data.name is Massachusetts, because name sits at the top level. The towns are in data.data, and the first town's name is data.data[0].name. You will read a model's reply the same way on Thursday 11/05, since it arrives as JSON too.

GET and POST in Network#

A GET puts everything in the URL, which is why a password must never go through one. A POST puts its data in the body. Click a request in Network: Payload shows the body, and Headers shows the rest, including X-Token on the message board.

Ask AI on Vercel#
  1. Open vercel.com/new, continue with GitHub, install the Vercel app if it asks, and import oim3690.
  2. Under Environment Variables, type OPENROUTER_API_KEY as the key. The value is the whole course key from the OpenRouter Class Key page.
  3. Click Deploy, then open https://<project>.vercel.app/ai-chat.html. The bare vercel.app link opens your index.html.

The course key has a shared limit of $5 for the whole class, and it works only with the model named in ask.js.

  • Keep the key in Vercel's settings only. If it ever reaches your repo, email me right away so I can revoke it.
  • Your function's URL is public. Anyone who finds it can call the model on the course key.

A model can go beside the API in your Mini Project 3, as the spec describes. For a key of your own, When a Key Leaks lists what to do first.

Anthropic's IPO filing#

After the lightning talk we opened Anthropic's S-1, the document a company files before an IPO. As reported, revenue for the first half of 2026 was about $16.3 billion. The net loss was about $80.7 billion, of which about $72.4 billion was a non-cash change in the value of convertible notes and similar instruments. The operating loss was about $693 million.