Create chat completion
const url = 'https://api.siteassist.io/v2/chat/completions';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"messages":[{"role":"user","content":"Hi"}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.siteassist.io/v2/chat/completions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "messages": [ { "role": "user", "content": "Hi" } ] }'Create a chat completion using the configured assistant. Supports streaming (Server-Sent Events) and non-streaming JSON responses. Streaming returns incremental tokens, while non-streaming returns the full completion along with token usage.
Authorizations
Section titled “Authorizations”Request Body
Section titled “Request Body”Messages and options for generating a chat completion. Set ‘stream’ to true to receive a text/event-stream response.
object
Assistant to use to generate the response. If not provided then will use the default assistant.
A list of messages comprising the conversation so far.
Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use developer messages for this purpose instead.
object
The role of the messages author, in this case system.
The contents of the system message.
Messages sent by an end user, containing prompts or additional context information.
object
The role of the messages author, in this case user.
The contents of the user message.
Messages sent by the model in response to user messages.
object
The role of the messages author, in this case assistant.
The contents of the assistant message.
If set to true, the model response data will be streamed to the client as it is generated using server-sent events.
Example
{ "messages": [ { "role": "user", "content": "Hi" } ]}Responses
Section titled “Responses”Successfully generated a chat completion
Server-sent events stream containing incremental updates of the assistant’s response in Vercel AI SDK UI stream format.
Example
data: {"type":"start"}
data: {"type":"start-step"}
data: {"type":"text-start","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","providerMetadata":{"openai":{"itemId":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18"}}}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"Hello! "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"How "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"can "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"I "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"assist "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"you "}
data: {"type":"text-delta","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18","delta":"today?"}
data: {"type":"text-end","id":"msg_68c276dd2b3481a2bb6da153039cf9cd093857e78e8e8f18"}
data: {"type":"finish-step"}
data: {"type":"finish"}
data: [DONE]Complete response when streaming is disabled. Contains full content, finish reason, and token usage.
object
Array of steps that make up the complete AI response
A single step in the AI response generation process
object
Array of content blocks in the response. Each block contains the generated content with its type and data.
object
The reason why the model stopped generating content. Common values include ‘stop’, ‘length’, ‘content_filter’, etc.
Token usage statistics for this response
object
Number of tokens in the input prompt
Number of tokens in the generated response
Total number of tokens used (input + output)
Number of tokens used for reasoning (for models that support it)
Number of input tokens that were cached and reused
Example
{ "steps": [ { "content": [ { "type": "text", "text": "Hello! How can I assist you today?" } ], "finishReason": "stop", "usage": { "inputTokens": 2409, "outputTokens": 11, "totalTokens": 2420, "reasoningTokens": 0, "cachedInputTokens": 0 } } ]}Successfully generated a non-streaming chat completion (full JSON response)
Complete response when streaming is disabled. Returned with 202 to indicate the completion was generated without streaming.
object
Array of steps that make up the complete AI response
A single step in the AI response generation process
object
Array of content blocks in the response. Each block contains the generated content with its type and data.
object
The reason why the model stopped generating content. Common values include ‘stop’, ‘length’, ‘content_filter’, etc.
Token usage statistics for this response
object
Number of tokens in the input prompt
Number of tokens in the generated response
Total number of tokens used (input + output)
Number of tokens used for reasoning (for models that support it)
Number of input tokens that were cached and reused
Example
{ "steps": [ { "content": [ { "type": "text", "text": "Hello! How can I assist you today?" } ], "finishReason": "stop", "usage": { "inputTokens": 2409, "outputTokens": 11, "totalTokens": 2420, "reasoningTokens": 0, "cachedInputTokens": 0 } } ]}Bad Request - The request body or parameters are invalid
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Invalid request body. Content is required.", "code": "INVALID_REQUEST_BODY", "details": { "field": "content" } }}Unauthorized - Authentication token is missing or invalid
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Authentication required", "code": "UNAUTHORIZED" }}Payment Required - A higher pricing plan is required to access the resource
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "A higher pricing plan is required to access this feature", "code": "PAYMENT_REQUIRED", "details": { "currentPlan": "free", "requiredPlan": "pro", "feature": "advanced_ai_models" } }}Forbidden - Access denied to the requested resource
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Access denied to this conversation", "code": "FORBIDDEN" }}Not Found - The requested resource was not found
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Conversation not found!", "code": "CONVERSATION_NOT_FOUND", "details": { "conversationId": "123e4567-e89b-12d3-a456-426614174000" } }}Conflict - The request could not be completed due to a conflict
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Resource already exists", "code": "CONFLICT", "details": { "resource": "conversation", "conflictingField": "id" } }}Unprocessable Entity - The request was well-formed but contains semantic errors
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Validation failed", "code": "VALIDATION_ERROR", "details": { "field": "content", "reason": "Content exceeds maximum length of 10000 characters" } }}Too Many Requests - Rate limit exceeded or quota reached
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Rate limit exceeded. Please try again later.", "code": "RATE_LIMIT_EXCEEDED", "details": { "retryAfter": 60 } }}Internal Server Error - An unexpected error occurred
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "An internal server error occurred", "code": "INTERNAL_SERVER_ERROR" }}Bad Gateway - The server received an invalid response from an upstream server
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Service temporarily unavailable", "code": "BAD_GATEWAY", "details": { "service": "ai_model_service" } }}Service Unavailable - The server is temporarily unable to handle the request
object
object
Human-readable error message describing what went wrong
Machine-readable error code for programmatic handling
Additional error details and context
object
Example
{ "error": { "message": "Service temporarily unavailable", "code": "SERVICE_UNAVAILABLE", "details": { "retryAfter": 30 } }}