Lesson 30 of 38 · Written learning
Integrate an LLM into a web application
Place model calls behind a clear software boundary with dependable errors and provider choices.
A common architecture has a user interface, an application backend, and a model provider. The backend can authenticate with the provider, check inputs, apply limits, and return a safe response. Never ship a private provider key in browser JavaScript. A provider abstraction can make it easier to switch services, but do not hide meaningful differences in model behavior or terms.
Handle the ordinary failure cases
Model requests can be slow, time out, fail due to rate limits, or return malformed output. Provide a clear loading state and a useful error message. Use bounded retries for transient errors, but avoid retrying forever. If an application uses JavaScript or TypeScript, keep request and response types explicit and validate data at runtime where it crosses a trust boundary.
- Set request timeouts and usage limits.
- Avoid sending unnecessary personal or confidential data.
- Return only the fields the interface needs.
- Keep provider credentials on the server and out of logs, commits, and browser responses.
Return to the LLM application engineering and agents stage · Suggested timing is flexible; move at your own pace.