> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reilabs.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completion

Generate a chat completion with a Reigent.

* **URL**: `/v1/chat/completions`
* **Method**: `POST`
* **Headers**:
  | Key | Value |
  | - | - |
  | Authorization | Bearer [**rei-agent-secret-token**](/docs/api-and-sdk/quickstart/#unit-api-key) |
* ## **Request**:

  **model** `string` Optional *Default*: Agent's Configured Model *Allowed values*:

  * `google/gemini-2.5-flash`

  ***

  **messages** `array` (min length: 1) Required

  <details>
    <summary>Show message structure</summary>
    Each message object contains:
    **role** `string` Required\
    The role of the message author.\
    *Allowed values: `"system"`, `"user"`, `"assistant"`, `"tool"`*
    **content** `string` or `array` Required\
    The contents of the message. Can be:

    * Simple text string
    * Array of content parts (for multimodal inputs)

    <details>
      <summary>Show content parts structure</summary>
      Each content part object contains:
      **type** `string` Required\
      The type of content part.\
      *Allowed values: `"text"`, `"image_url"`, `"file"`, `"file_url"`*
      **text** `string` Conditional\
      Text content (required when type is `"text"`)
      **image\_url** `object` Conditional\
      Image URL details (required when type is `"image_url"`)\
      *Contains:*

      * **url** `string` Required\
        The URL of the image

      <br />

      **file** `object` Conditional\
      File details (required when type is `"file"`)\
      *Contains:*

      * **filename** `string` Required\
        The name of the file
      * **file\_data** `string` Required\
        The buffer content of the file

      <br />

      **file\_url** `string` Conditional\
      The URL of the file (required when type is `"file_url"`)
    </details>

    **name** `string` Optional\
    An optional name for the participant
    **tool\_call\_id** `string` Optional\
    Required when role is `"tool"`
    **tool\_calls** `array` Optional\
    Tool calls made by the assistant
  </details>

  ***

  ## **temperature** `number` Optional *Range*: 0 to 2 *Default*: 1

  ## **max\_tokens** `integer` Optional *Minimum*: 1

  ## **top\_p** `number` Optional *Range*: 0 to 1

  ## **n** `integer` Optional *Minimum*: 1

  ## **seed** `number` Optional *Range*: 0 to 2^53-1

  ## **stream** `boolean` Optional

  ## **stop** `string` or `array[string]` Optional

  ## **presence\_penalty** `number` Optional *Range*: -2.0 to 2.0

  ## **frequency\_penalty** `number` Optional *Range*: -2.0 to 2.0

  ## **logit\_bias** `object` Optional *Key format*: Token IDs as string numbers *Value range*: -100 to 100

  ## **logprobs** `boolean` Optional

  ## ***top\_logprobs*** `number` Optional

  ## **user** `string` Optional

  **response\_format** `object` Optional Specifies the format of the model's output. Use this to request structured responses.

  <details>
    <summary>Show response\_format structure</summary>
    **type** `string` Required
    The type of response format.
    *Allowed values: `"text"`, `"json_object"`, `"json_schema"`*

    * `"text"` - Standard text response (default)
    * `"json_object"` - Response will be valid JSON
    * `"json_schema"` - Response will conform to a specified JSON schema
      **json\_schema** `object` Conditional
      Schema definition (required when type is `"json_schema"`)
      *Contains:*
    * **name** `string` Required
      The name of the schema
    * **strict** `boolean` Optional
      Whether to enforce strict schema adherence. Default: `false`
    * **schema** `object` Required
      JSON Schema definition with:
      * **type** `string` - Schema type (e.g., `"object"`)
      * **properties** `object` - Property definitions
      * **required** `array` - Required property names
      * **additionalProperties** `boolean` - Allow extra properties
  </details>

  ***

  **tools** `array` Optional<br />A list of tools the model may call

  <details>
    <summary>Show tool structure</summary>
    Each tool object contains:
    **type** `string` Required\
    *Must be: `"function"`*
    **function** `object` Required\
    The function definition
    **function.name** `string` Required\
    The name of the function
    **function.parameters** `object` Required\
    The parameters the function accepts
  </details>

  ***

  **tool\_choice** `string` or `object` Optional<br />Controls which tool is called<br />*Allowed string values: `"none"`, `"auto"`*<br />*Or specify a tool with:*

  ```json theme={null}
  {
    "type": "function",
    "function": {
      "name": "tool_name"
    }
  }
  ```

***

* **Sample Request**

1. **Type: Text**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
      "messages": [
          {
              "role": "user",
              "content": "Hello, can you help me with my research?"
          }
      ],
      "tools": [
          {
              "type": "function",
              "function": {
                  "name": "get_weather",
                  "description": "Get current temperature of given location",
                  "parameters": {
                      "type": "object",
                      "properties": {
                          "location": {
                              "type": "string",
                              "description": "City and country (e.g. Paris, France)"
                          }
                      },
                      "required": ["location"],
                      "additionalProperties": false
                  },
                  "strict": true
              }
          }
      ]
  };
  ```
</details>

2. **Type: Image (in URL)**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
      "messages": [
          {
              "role": "user",
              "content": [
                {
                  "type": "text",
                  "text": "Hello, can you help me with my research?"
                },
                {
                  "type": "image_url",
                  "image_url": {
                    "url": "https://test.png"
                  }
                },
              ]
          }
      ],
      "tools": []
  };
  ```
</details>

3. **Type: Image (in Base64)**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
      "messages": [
          {
              "role": "user",
              "content": [
                {
                  "type": "text",
                  "text": "Hello, can you help me with my research?"
                },
                {
                  "type": "image_url",
                  "image_url": {
                    "url": "data:image/png;base64,iV..."
                  }
                },
              ]
          }
      ],
      "tools": []
  };
  ```
</details>

4. **Type: Docs (PDF)**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
      "messages": [
          {
              "role": "user",
              "content": [
                {
                  "type": "text",
                  "text": "Hello, what's inside the PDF?"
                },
                {
                  "type": "file",
                  "file": {
                    "filename": "Sample File Name",
                    "file_data": "data:application/pdf;base64,JVBERi0xLjMNCiXi48/....",
                  }
                }
              ]
          }
      ],
      "tools": []
  };
  ```
</details>

5. **Type: Docs**

* Supported File Types: - `json`, `xlsx`, `xlsm`, `csv`, `md`, `pptx`, `docx`, `txt`

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
      "messages": [
          {
              "role": "user",
              "content": [
                {
                  "type": "text",
                  "text": "Hello, what's inside the PDF?"
                },
                {
                  "type": "input_file",
                  "file_url": "https://file_url",
                }
              ]
          }
      ],
      "tools": []
  };
  ```
</details>

6. **Type: JSON Schema Response**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
    "model": "google/gemini-2.5-flash",
    "messages": [
      {
        "role": "user",
        "content": "Tell me about a cat named Whiskers. Return the response as a JSON object with the following fields: 'name' (string), 'color' (string - the cat's fur color), 'age' (integer - in years), and 'personality' (string - brief description). Make sure to include all required fields."
      }
    ],
    "response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "cat_info",
        "strict": true,
        "schema": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "description": "The cat's name"
            },
            "color": {
              "type": "string",
              "description": "The cat's fur color"
            },
            "age": {
              "type": "integer",
              "description": "The cat's age in years"
            },
            "personality": {
              "type": "string",
              "description": "Brief description of the cat's personality"
            }
          },
          "required": ["name", "color", "age", "personality"],
          "additionalProperties": false
        }
      }
    }
  }
  ```
</details>

***

* **Response**:

1. **Without Tools**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
    "choices": [
      {
        "index": 0,
        "message": {
          "content": "Hello! How can I assist you today?",
          "role": "assistant"
        }
      }
    ]
  }
  ```
</details>

2. **With Tools**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
    "choices": [
      {
        "index": 0,
        "message": {
          "content": "",
          "role": "assistant",
          "tool_calls": [
            {
              "id": "call_zSIBPi4QKxjkpAewfi5YbTnI",
              "type": "function",
              "function": {
                "name": "get_weather",
                "arguments": "{\"location\":\"Paris, France\"}"
              }
            }
          ]
        }
      }
    ]
  }
  ```
</details>

3. **With JSON Schema**

<details>
  <summary>Show sample</summary>

  ```json theme={null}
  {
    "choices": [
      {
        "index": 0,
        "message": {
          "content": "{\"name\":\"Whiskers\",\"color\":\"orange tabby\",\"age\":3,\"personality\":\"Playful and curious, loves to explore and cuddle\"}",
          "role": "assistant"
        }
      }
    ]
  }
  ```
</details>

***

* **Error**

| Response Code | Reason |
| - | - |
| 400 | Validation Error |
| 401 | Unauthorized |
| 404 | Agent not found |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.