Example result: Add an AI feature to your app with an LLM API
AI-generated example · Build · AI Feature
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.

text-code-ai-feature-llm-api — claude — 91 words

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

What you will get

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.

Common mistake

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.

Also watch for
  • 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.
Try a variation: guard against prompt injection

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.

Still not right? Reply with this

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 →