Fastify Backend Server
A Fastify backend using @caesura-io/openai with OpenAI Responses and Chat Completions, including streaming. It demonstrates explicit conversation creation and logs analysis and credit events.
Source and full walkthrough: node-openai-server.
Run
Requires Node.js 22+, an OpenAI API key, and a CaesuraO API key. Clone the examples repository, then:
cd examples/node-openai-server
npm ci
cp .env.example .env
# Set OPENAI_API_KEY and CAESURA_API_KEY in .env.
npm run dev
The server runs at http://localhost:3001. The SDK defaults to https://api.caesurao.com; normally omit CAESURA_BASE_URL.
Follow a conversation
- Call
POST /conversationsonce and retain the returnedconversationId. - Pass that ID in the HTTP body's
conversationIdfield for/v1/responses,/v1/responses/stream, or/v1/chat/completions. - Send growing application dialogue, including actual model replies, using normal
userandassistantroles. Use a distinct ID for each independent conversation.
The server passes { caesura: { conversationId } } as the second SDK argument. Its HTTP routes require an ID; the OpenAI user field is not used for this purpose. The repository's requests.http provides complete multi-turn requests.
Behavior to observe
The example uses mode: 'sync', so analysis finishes before model generation or streaming starts. Console events show requests, full analysis values, buffering, injection, errors, and reported credits. An analysis failure can leave the model call running; inspect SDK events as well as the HTTP response.
Persistence is enabled by default. Set CAESURA_PERSIST=false and restart to use stable local labels without backend saving. Explicit backend IDs survive application restarts when saved by your application; local guidance and credit history remain in memory. See Conversations & Persistence.
Provider and CaesuraO keys stay on the server and go only to their respective services. Dialogue is sent to both for generation and analysis. Keep injected guidance separate from application dialogue history.