> For the complete documentation index, see [llms.txt](https://0xreisearch.gitbook.io/0xreisearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xreisearch.gitbook.io/0xreisearch/factory-and-core-api-sdk-cross-framework/api-reference/chat-completion.md).

# Chat Completion

Chat completion by Reigent.

* **URL**: `/rei/agents/chat-completion`
* **Method**: `POST`
* **Headers**:

  | Key           | Value                             |
  | ------------- | --------------------------------- |
  | Authorization | Bearer **rei-agent-secret-token** |
* **Request**:

```
{
    "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
            }
        }
    ]
};
```

* **Response:**

without tools

```
{
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "Hello! How can I assist you today?",
        "role": "assistant"
      }
    }
  ]
}
```

with tools

```
{
  "choices": [
    {
      "index": 0,
      "message": {
        "content": "",
        "role": "assistant",
        "tool_calls": [
          {
            "id": "call_zSIBPi4QKxjkpAewfi5YbTnI",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\":\"Paris, France\"}"
            }
          }
        ]
      }
    }
  ]
}
```

* **Error**

| Response Code | Reason          |
| ------------- | --------------- |
| 401           | Unauthorized    |
| 404           | Agent not found |
