BoilerPrompt
Claude Code

Claude Code prompt to integrate an LLM chatbot

Chatbot integrations fail in the unglamorous places: leaked keys, broken streams, lost history. This prompt directs Claude Code to plan file placement before coding, mock the provider in tests, and grep the built client bundle from the terminal to confirm the API key never ships to the browser.

Last updated

Prompt
Integrate a streaming LLM chatbot into this app. Read the existing code first and list where the chat UI, API route, and provider client should live before writing anything. Requirements: a server-side route that streams tokens to the client over SSE, chat history stored in {{database}} keyed by conversation id, the provider API key read from an environment variable and never bundled client-side. Add a system prompt file at prompts/system.md so it can be edited without a deploy. Handle three failure paths distinctly: provider timeout, rate limit response, and a mid-stream disconnect that keeps the partial transcript. Write an integration test that mocks the provider and asserts the stream terminates cleanly. Run the test suite, then grep the built client bundle for the key variable name to prove no leak, and list every file you touched.

Customize it

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

Your customized prompt
Integrate a streaming LLM chatbot into this app. Read the existing code first and list where the chat UI, API route, and provider client should live before writing anything. Requirements: a server-side route that streams tokens to the client over SSE, chat history stored in PostgreSQL keyed by conversation id, the provider API key read from an environment variable and never bundled client-side. Add a system prompt file at prompts/system.md so it can be edited without a deploy. Handle three failure paths distinctly: provider timeout, rate limit response, and a mid-stream disconnect that keeps the partial transcript. Write an integration test that mocks the provider and asserts the stream terminates cleanly. Run the test suite, then grep the built client bundle for the key variable name to prove no leak, and list every file you touched.

Same task in other tools

Questions about this prompt

Can Claude Code exercise the streaming path without spending tokens on the real provider?

Yes. The integration test mocks the provider, so stream setup, chunk handling, and clean termination all run offline. For one live smoke test, export your key in the shell and ask the agent to curl the route once.

How do I turn this into a RAG chatbot over my own docs?

Tell the agent where the documents live and ask for a retrieval step that injects the top matching chunks ahead of the system prompt file. The bundle grep and the disconnect handling carry over unchanged.

Users disconnect mid-answer and the transcript vanishes. Why?

History was probably written only after the stream completed. The prompt requires a mid-stream disconnect to keep the partial transcript, which forces incremental writes; if the agent skipped that, ask it to persist per flushed chunk and re-run the disconnect test.

Related prompts