
- Updated
Add an AI feature to your app with an LLM API
This prompt builds a server-side AI feature, such as summarising reviews, with a clear system prompt, error handling, structured JSON output and cost limits. The API key stays on the server.
Act as a developer who has shipped features using LLM APIs. Feature: [e.g. summarise customer reviews into pros and cons] Stack: [e.g. Next.js server route] API: [e.g. the Claude or OpenAI API] Write the server-side code that calls the API with a clear system prompt, handles errors, timeouts and rate limits, and returns structured JSON I can render. Keep the API key on the server. Add a simple way to limit cost (input size, caching, per-user limits), and give me five test inputs, including tricky ones, to check the output quality.
Keep the API key on the server, never in frontend code. Anyone can read a key that ships to the browser.
Get a better result
Server-side code that calls the API with a clear system prompt, handles errors, timeouts and rate limits, returns structured JSON and includes cost limits, plus five test inputs including awkward ones.
The code uses an old model name or a parameter that no longer exists.
Fix: Check the provider’s current documentation for model names and options before you run it, and paste the docs snippet into the prompt.
- The JSON sometimes comes back broken. Ask for validation of the response against a schema, with one retry and a safe fallback message if it still fails.
- Costs grow because long inputs are not limited. Add a maximum input length, a per-user daily limit and caching of repeated requests, and log token use.
Ask for “a short section on what happens if the user input says to ignore the instructions, and how to keep that text separate from the system prompt”. Test it with the tricky inputs.
Add input length limits, a per-user rate limit and response caching. Show where each lives and how to turn it off while testing.
Guides that use this prompt
More chat & writing prompts
See all 465 →More like this
- Build a REST API endpoint with validationClaude · ChatGPT · Gemini
- Fix a CORS error between frontend and APIClaude · ChatGPT · Gemini
- Mock an external API in your testsClaude · ChatGPT · Gemini
- Speed up a slow API endpoint or functionClaude · ChatGPT · Gemini
- Write a Dockerfile for your appClaude · ChatGPT · Claude Code



