BoilerPrompt
Cursor

Cursor prompt to integrate an LLM chatbot

Wire a chatbot into an existing app with the provider key kept server side and responses streamed token by token. Run this in Cursor Agent mode and you get a single chat endpoint, a panel component with an abort button, session history in your database, and a system prompt that lives in a file you can diff.

Last updated

Prompt
Integrate an LLM chatbot into this app behind a single POST /api/chat endpoint. Keep the provider API key server side, read it from an environment variable, and fail with a clear message at startup if it is missing rather than at the first request. Stream tokens to the client over server-sent events and render them incrementally in a chat panel component, with a stop button that aborts the fetch. Persist conversation history per session in {{database}} and send only the last ten messages as context. Put the system prompt in its own versioned file, prompts/chat-system.txt, not inline in code. Add one test that mocks the provider and asserts the endpoint streams and stores messages. Run lint and tests in the terminal, then list changed files with a one-line reason for each.

Customize it

Runs in your browser. Nothing you type here is sent anywhere.

Your customized prompt
Integrate an LLM chatbot into this app behind a single POST /api/chat endpoint. Keep the provider API key server side, read it from an environment variable, and fail with a clear message at startup if it is missing rather than at the first request. Stream tokens to the client over server-sent events and render them incrementally in a chat panel component, with a stop button that aborts the fetch. Persist conversation history per session in PostgreSQL and send only the last ten messages as context. Put the system prompt in its own versioned file, prompts/chat-system.txt, not inline in code. Add one test that mocks the provider and asserts the endpoint streams and stores messages. Run lint and tests in the terminal, then list changed files with a one-line reason for each.

Same task in other tools

Questions about this prompt

Which LLM provider does this prompt assume?

None by name. The agent picks whatever SDK is already in your lockfile, so if you are starting clean, name the provider in the first line. The endpoint shape stays the same, only the streaming adapter changes.

Streaming works in production but not in dev, or the reverse. What breaks it?

Dev proxies and compression middleware buffer server-sent events. Exempt the chat route from compression and check your framework's dev proxy config. If the stop button does nothing, the server-side reader was never cancelled when the fetch aborted.

How do I grow this into retrieval or tool calling?

Keep this as the base, then ask a follow-up to insert a retrieval step before the provider call or add tool definitions to the request. Because the system prompt lives in its own file, those changes arrive as clean diffs you can review separately.

Related prompts