# 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 |
