Fastify Backend Server
This example demonstrates a minimal Fastify backend exposing standard OpenAI-compatible HTTP endpoints using the @caesura-io/openai wrapper.
Source Code: caesura-io/examples-sdk-js/examples/node-openai-server
What this shows
A server-side integration wrapping the official OpenAI Node SDK, logging injected recommendations and credit usage to the console. It uses gpt-5.4-mini via both the newer Responses API and the older Chat Completions API.
When to use it: Use the @caesura-io/openai package when you are building a headless service, backend worker, or an application that already uses the official openai package directly.
Prerequisites
- Node.js v22 or higher
- An OpenAI API key
- A Caesura API key (see Authentication)
Setup
- Clone the examples repository.
- Navigate to the example directory:
cd examples/node-openai-server
- Copy the example environment file:
cp .env.example .env
- Fill in your
OPENAI_API_KEYandCAESURA_API_KEYin.env. Ensure your Caesura environment base URL is correctly set if you are not using the default. - Install dependencies:
npm install
Run
Run the server using Node's native --env-file support and tsx (which executes TypeScript directly):
npm run dev
Note: The dev script in package.json maps to npx tsx --env-file=.env src/server.ts.
What you'll see
You can use the included requests.http file (or curl) to ping the server.
In your console, you will see Fastify startup logs alongside detailed Caesura lifecycle events:
- The requests sent to Caesura's backend for analysis
- The resulting recommendations
- When a recommendation is injected into your OpenAI request
Data Flow
Because Caesura operates as a middleware/proxy, it is important to understand where your data goes:
- Provider API Key (OpenAI): Sent only to OpenAI. It is never sent to the Caesura backend. This key remains securely on your server.
- Conversation Content: Sent to the Caesura backend for analysis, and to the provider for language model generation.
- Caesura API Key: Sent only to the Caesura backend.