---
title: "Create a guarded chat completion"
method: POST
path: "/v1/chat/completions"
tags: ["Chat Completions"]
---

# Create a guarded chat completion

`POST /v1/chat/completions`

Generate a chat completion with guardrails applied.

The request shape is compatible with the OpenAI Chat Completions API and
accepts Guardrails-specific options in the `guardrails` object.

## Request body

- GuardrailsChatCompletionRequest
  - `model` string, required — LLM model to use for the completion.
  - `messages` ChatMessage[] — Chat messages in the current conversation.
    - `role` string, required — Message role, such as `system`, `user`, `assistant`, `tool`, or `context`.
    - `content` union, required — Message content.
      - string
      - object[]
  - `stream` boolean — Return partial message deltas as server-sent events.
  - `max_tokens` integer — Maximum number of tokens to generate.
  - `temperature` number, float — Sampling temperature.
  - `top_p` number, float — Top-p sampling parameter.
  - `stop` union — Stop sequence or sequences.
    - string
    - string[]
  - `presence_penalty` number, float — Presence penalty parameter.
  - `frequency_penalty` number, float — Frequency penalty parameter.
  - `function_call` object — Function call parameter.
  - `logit_bias` object — Logit bias parameter.
  - `logprobs` boolean — Log probabilities parameter.
  - `guardrails` GuardrailsRequestOptions — Guardrails-specific request options.
    - `config_id` string — Guardrails configuration ID to use. Mutually exclusive with `config_ids`.
    - `config_ids` string[] — List of configuration IDs to combine. Mutually exclusive with `config_id`.
    - `thread_id` string — Existing thread ID for Colang 1.0 conversation persistence.
    - `context` object — Additional context data for the conversation.
    - `options` GenerationOptions
      - `rails` GenerationRailsOptions
        - `input` union — Enable, disable, or select named rails.
          - boolean
          - string[]
        - `output` union — Enable, disable, or select named rails.
          - boolean
          - string[]
        - `retrieval` union — Enable, disable, or select named rails.
          - boolean
          - string[]
        - `dialog` boolean — Enable dialog rails.
        - `tool_input` union — Enable, disable, or select named rails.
          - boolean
          - string[]
        - `tool_output` union — Enable, disable, or select named rails.
          - boolean
          - string[]
      - `llm_params` object — Additional parameters to pass to the LLM call.
      - `llm_output` boolean — Include custom LLM output in the response.
      - `output_vars` union — Context variables to return.
        - boolean
        - string[]
      - `log` GenerationLogOptions
        - `activated_rails` boolean — Include information about activated rails.
        - `llm_calls` boolean — Include details about LLM calls.
        - `internal_events` boolean — Include internal generated events.
        - `colang_history` boolean — Include conversation history in Colang format.
    - `state` object — Colang 1.0 transcript state for continuing a previous interaction.

## Response `200`

Chat completion response or server-sent event stream.

- GuardrailsChatCompletion
  - `id` string
  - `object` string
  - `created` integer
  - `model` string
  - `choices` ChatCompletionChoice[]
    - `index` integer
    - `message` ChatMessage
      - `role` string, required — Message role, such as `system`, `user`, `assistant`, `tool`, or `context`.
      - `content` union, required — Message content.
        - string
        - object[]
    - `finish_reason` string, nullable
  - `guardrails` GuardrailsResponseData
    - `config_id` string, nullable
    - `state` object, nullable
    - `llm_output` object, nullable
    - `output_data` object, nullable
    - `log` object, nullable

## Other responses

- `422` — Invalid request or unsupported state continuation.

---

[API](https://skmtc.net/nvidia/apis/nvidia-nemo-guardrails-library-api-server.md) · [All operations](https://skmtc.net/nvidia/apis/nvidia-nemo-guardrails-library-api-server/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/nvidia/nvidia-nemo-guardrails-library-api-server/versions/78af1d0a3dfe/schema)
