Fastify Backend Server
A Fastify backend using @caesura-io/openai for Responses, Chat Completions, and streaming.
Source and setup · Repository setup
Use Node.js 22 or newer. In the example directory, run npm ci, copy .env.example to .env, set OPENAI_API_KEY and CAESURA_API_KEY, and run npm run dev. Dependencies are installed from npm. Both API keys remain server-side.
What it demonstrates
- Call
POST /conversationsonce and save the returnedconversationId. - Send that ID and a stable customer
messageIdto/v1/responses,/v1/responses/stream, or/v1/chat/completions. - Supply growing participant dialogue, including actual model replies. Use a new message ID for each distinct customer message, and another conversation ID for an independent chat.
With the server running, use npm run demo in another terminal to create a conversation and make two Responses calls, reusing its ID and the actual first reply. This uses real API credits. Alternatively, run requests.http in order with the JetBrains HTTP Client; its handlers capture conversation IDs and replies automatically.
The example uses mode: 'sync' and failurePolicy: 'throw', so failed analysis prevents provider generation. It validates customer turns and logs analysis and credit events. The OpenAI user field is not used as conversation identity.
Saving is enabled by default. It stores customer messages, their analyses, and completed agent replies in the same conversation. CAESURA_PERSIST=false disables that save but does not permit invented conversation IDs. See Conversations & Persistence.
The example is a local integration demonstration. Add caller authentication and conversation ownership checks before exposing its routes publicly.