Skip to main content

POST /v1/chat/completions

Create a chat completion with guardrails applied. This endpoint is compatible with the OpenAI Chat Completions API with additional guardrails-specific extensions.

Request

string
required
The LLM model to use for chat completion (e.g., “gpt-4o”, “llama-3.1-8b”).
array
The list of messages in the current conversation.
boolean
default:"false"
If set, partial message deltas will be sent as server-sent events.
integer
The maximum number of tokens to generate.
number
Sampling temperature to use (0.0 to 2.0).
number
Top-p sampling parameter (0.0 to 1.0).
string | array
Stop sequences where the API will stop generating further tokens.
number
Presence penalty parameter (-2.0 to 2.0).
number
Frequency penalty parameter (-2.0 to 2.0).

Guardrails Extensions

object
Guardrails-specific options:
string
The guardrails configuration ID to use.
array
List of configuration IDs to combine. Cannot be used with config_id.
string
The ID of an existing thread to continue (minimum 16 characters).
object
Additional context data for the conversation.
GenerationOptions
Additional generation options:
  • rails: Which rails to enable ({"input": true, "output": true})
  • log: Logging options ({"activated_rails": true, "llm_calls": true})
  • output_vars: Variables to extract from context
object
State object to continue the interaction. Must contain events or state key.

Response

string
Unique identifier for the chat completion.
string
Always “chat.completion”.
integer
Unix timestamp of when the completion was created.
string
The model used for the completion.
array
Array of completion choices.
integer
The index of this choice.
object
The generated message.
string
Always “assistant”.
string
The content of the message.
array
Tool calls generated by the model (if any).
string
The reason the generation stopped: “stop”, “length”, or “content_filter”.
object
Guardrails-specific output data:
string
The configuration ID that was used.
object
Updated state object for continuing the conversation.
object
Generation log data (if requested):
  • activated_rails: List of rails that were activated
  • llm_calls: Details of LLM calls made
  • stats: Performance statistics

Response Examples

Error Responses

object
string
Human-readable error message.
string
Error type: “invalid_request_error”, “authentication_error”, “server_error”, etc.
string
Error code.