Building AI Features in JavaScript
Learning Path ⋅ Skills: Model API Calls, Token Costs, Structured Output, Schema Validation, Streaming, Conversation History, Embeddings and Search, Tool Calling, Prompt Injection, Evals
This path is for you if you’ve finished Async JavaScript and Web APIs, or already know fetch(), async and await, error handling, and Node scripts with npm. You’ve used AI chat tools but never built on a model. You’ll treat the model as an outside service that costs money, can fail, and can be wrong. Your code works with OpenAI or Anthropic.
Each course tells one story. You’ll draft replies to a tea importer’s emails, turn a vet clinic’s booking notes into checked records, and stream a language club’s practice partner to a web page. Then you’ll answer players’ questions from a board-game café’s rulebooks and build a ferry company’s booking assistant.
Every course has exercises, a project, and a quiz. In the last course, you build the booking assistant from a brief without a walkthrough, then use evals to show that a change to the prompt or the model made it better.
Building AI Features in JavaScript
Learning Path ⋅ 6 Resources
Is this path right for you? Mentor AI knows what’s in it and can help you decide where to begin.
Call a Model and Check What It Returns
Start by calling OpenAI or Anthropic from a Node script through one small module that prices every call and handles rate limits and timeouts. Then you’ll turn free-text notes into JSON records, check them with Zod, retry a bad answer once, and send the rest to a person.
Course
Calling a Language Model From JavaScript
Call a language model from JavaScript with one module for OpenAI or Anthropic. Price every call and handle rate limits, timeouts, and cut-off replies.
Course
Structured Output From Language Models
Turn free-text notes into data with a language model: prompt for JSON that fits a schema, check it with Zod, and retry or hand off.
Stream Answers to a Web Page
With the model module working, move it behind an Express server. You’ll stream each reply to a web page word by word, keep a long conversation within a token budget, and add a Stop button that also ends the server’s call to the model.
Course
Streaming AI Answers to a Web Page
Stream a model's answer from a Node server to a web page as it's written, keep the conversation's history within a token budget, and let the user stop an answer and its bill, with the API key kept on the server.
Answer Questions From Your Own Documents
Next, you’ll answer questions from text you control. Split rulebooks into chunks, embed them locally, and search them by meaning. Then have the model answer only from what the search found, cite its sources, and say so when the documents don’t cover the question.
Course
Answering Questions From Your Own Documents
Split documents into chunks, embed them locally, search them by meaning, and have a model answer only from what the search found, citing its sources and saying when the documents don't cover the question.
Let a Model Act Safely and Measure It
In the last course, the model calls your own functions. You’ll check every tool call’s arguments, confirm a change before making it, and keep instructions hidden in a booking note from taking over. Then you’ll write an eval set and use it to compare two versions before you switch.
Course
Tools, Guardrails and Evals for AI Features
Let a language model call your own JavaScript functions safely: check its arguments, confirm changes, limit what it can reach, resist instructions hidden in data, and prove a change with an eval set.
Test Your Knowledge
You’ve made it through the path! In the wrap-up quiz below, you’ll revisit model calls and their costs, structured output checked with Zod, streaming answers, answers from your own documents, and safe tool calls measured with evals.
Interactive Quiz
Building AI Features in JavaScript
Check what you learned in Building AI Features in JavaScript, from model calls and Zod checks to streaming, document answers, tools, and evals.
Congratulations on completing this learning path! You can now call a language model from JavaScript, keep your API key secret, price every call, and recover from rate limits and timeouts. You can turn free text into data that Zod checks, and stream answers from a Node server to a web page.
You can also answer questions from your own documents with their sources cited, let a model call your functions without letting it do harm, and use an eval set to show whether a change made a feature better.
You might also be interested in these related learning paths:
Got feedback on this learning path?
Looking for real-time conversation? Visit the RealJS Community Chat or join the next “Office Hours” Live Q&A Session. Happy coding!