POST /v1/chat) provides a simple request/response pattern where the entire assistant message is returned once it’s fully generated.
Endpoint
Request Headers
x-widget-api-key instead of x-api-key.
Request Body
Parameters
Unique identifier for the user session. Must be 1-128 characters, alphanumeric with
._:- allowed.The user’s message. Must be 1-4000 characters.
Response Format
On success, returns a200 OK status with the following JSON:
Response Fields
The unique ID of the conversation. This is automatically created or retrieved based on the
sessionId.The complete assistant response message.
Example Usage
Here’s a complete example using the Fetch API:Error Responses
400 Bad Request
Returned when the request payload is invalid:- Missing required fields
sessionIddoesn’t match the required patternmessageis empty or exceeds 4000 characters
401 Unauthorized
Returned when authentication fails:- Missing API key header
- Invalid API key
429 Too Many Requests
Returned when rate limit is exceeded:500 Internal Server Error
Returned when an unexpected error occurs:How It Works
When you send a message to/v1/chat, the backend:
- Validates your API key and request payload (backend/src/server.ts:479-506)
- Creates or retrieves the conversation based on
sessionId - Adds your message to the conversation history
- Sends the conversation history to OpenAI
- Waits for the complete response to be generated
- Saves the assistant’s message to the database
- Returns the complete response to you
The conversation history is automatically maintained across messages with the same
sessionId. The API includes up to the most recent messages in each request to provide context.