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

# HTTP Call

> Configure an HTTP_CALL function to integrate an agent with APIs and webhooks.

# HTTP Call

`HTTP_CALL` lets the AI call an API, endpoint, or webhook during a conversation. The function tool name must match the configuration `config_key`.

## Configuration

```json theme={null}
{
  "function_type": "HTTP_CALL",
  "url": "https://seu-endpoint/webhook",
  "method": "POST",
  "timeout": 10000,
  "run_ai_after": true,
  "error_message": "The information could not be retrieved.",
  "tool": {
    "description": "Retrieves information about a motorcycle.",
    "fields": [
      {
        "name": "info",
        "type": "enum",
        "values": ["prices", "details"],
        "description": "Information to retrieve.",
        "required": true
      },
      {
        "name": "moto_id",
        "type": "string",
        "description": "Motorcycle identifier.",
        "required": true
      }
    ]
  }
}
```

| Field           | Required | Purpose                                                        |
| --------------- | -------- | -------------------------------------------------------------- |
| `url`           | Yes      | Endpoint to call                                               |
| `method`        | Yes      | HTTP method, usually `POST`                                    |
| `function_type` | Yes      | Must be `HTTP_CALL`                                            |
| `auth`          | No       | `bearer`, `api_key`, or `basic` authentication                 |
| `timeout`       | No       | Timeout in milliseconds                                        |
| `run_ai_after`  | No       | Allows the AI to continue after the response, including errors |
| `error_message` | No       | Fallback message when the request fails                        |

The tool may declare zero to 20 variables of type `string`, `number`, `integer`, `boolean`, or `enum`.

## Webhook authentication

When the endpoint uses a bearer token, configure a header:

```text theme={null}
Name: Authorization
Value: Bearer SEU_TOKEN
```

## Outgoing request

```json theme={null}
{
  "params": {},
  "query": {},
  "body": {
    "function_args": {
      "info": "prices",
      "moto_id": "xr-300l-tornado"
    },
    "project": {
      "id": 36,
      "account_id": 5,
      "inbox_id": 156
    },
    "contact": {
      "conversation_id": 17765,
      "source_id": "487",
      "identifier": "+551199998888",
      "name": "Example contact",
      "configurations_set": "compra",
      "custom_infos": {},
      "additional_data": {},
      "file_ids": [],
      "vector_store_id": null
    }
  }
}
```

The request may also include `config_fields` when this content is configured in `additional_data`.

## Expected response

```json theme={null}
{
  "output": "The XR 300L Tornado costs ...",
  "continue_conversation": true,
  "direct_messages": [
    {
      "type": "video",
      "url": "https://seu-dominio.com/arquivo.mp4",
      "content": "Product overview video",
      "active_in_chat": true
    }
  ],
  "add_label": ["qualified"],
  "remove_label": ["new"]
}
```

| Field                   | Purpose                                                                            |
| ----------------------- | ---------------------------------------------------------------------------------- |
| `output`                | Text result delivered to the AI; required and must be a string                     |
| `continue_conversation` | When `true`, calls the AI again with the output in the history; defaults to `true` |
| `message_to_ai`         | Additional instruction for the AI                                                  |
| `direct_messages`       | Content sent directly to the contact before the AI continues                       |

## Direct messages

`direct_messages` accepts:

* Text: `{ "type": "text", "content": "..." }`
* Audio: `{ "type": "audio", "url": "..." }`
* Video: `{ "type": "video", "url": "..." }`
* Image: `{ "type": "image", "url": "...", "content": "optional caption" }`
* Document by URL: `{ "type": "document", "url": "...", "content": "...", "filename": "contract.pdf" }`

All types optionally accept `active_in_chat`. Binary documents can be returned as `multipart/form-data`, with a `json` part and a binary part whose name matches the `filename` declared in the JSON.

## Timeout

The maximum effective timeout is 60 seconds. A missing, invalid, zero, or negative value also results in a 60-second timeout.
