# HTTP API for Agents

The **HTTP API for Agents** lets you connect your Tila agent to any external system via HTTP requests. Use it to integrate your agent into apps, chatbots, automations, or backend logic.

## Endpoint

Each agent is available at:

```
https://tila.ai/channel/api/{channelId}
```

Where `{channelId}` is your agent’s unique identifier.

## Parameters

- **input** (string) — Your request or instruction for the agent.
- **threadId** (string, optional) — Dialog/session ID. If omitted, a new conversation starts.

## GET Request

**Start a new dialog**

```bash
curl -X GET "https://tila.ai/channel/api/12345?input=hello"
```

**Continue a dialog**

```bash
curl -X GET "https://tila.ai/channel/api/12345?threadId=681a191ad74ee8d89080289a"
```

**Example response**

```json
{
  "threadId": "681a191ad74ee8d89080289a",
  "content": "Hello! How can I help you today?",
  "messages": [
    {
      "id": "681a191ad74ee8d89080289d",
      "content": "Hello! How can I help you today?",
      "annotations": []
    }
  ],
  "images": []
}
```

- `threadId` — Save and reuse for continued dialogs.
- `content` — Agent reply (Markdown by default).
- `messages` — Array with all reply parts.
- `images` — Array of image URLs, if any were generated.

## POST Request (JSON)

**Start a new dialog**

```bash
curl -X POST "https://tila.ai/channel/api/12345" \
  -H "Content-Type: application/json" \
  -d '{"input":"hello"}'
```

**Continue a dialog**

```bash
curl -X POST "https://tila.ai/channel/api/12345" \
  -H "Content-Type: application/json" \
  -d '{"input":"hello","threadId":"681a191ad74ee8d89080289a"}'
```

## Authentication

If your channel is protected by an API key, add this header:

```bash
-H "Authorization: <API_KEY>"
```

**Example:**

```bash
curl -X POST "https://tila.ai/channel/api/12345" \
  -H "Authorization: abcdef123456" \
  -H "Content-Type: application/json" \
  -d '{"input":"hello"}'
```

## File Upload (multipart/form-data)

Send files to the agent via the `files` field. Multiple files are supported:

```bash
curl -X POST "https://tila.ai/channel/api/12345" \
  -H "Authorization: abcdef123456" \
  -H "Content-Type: multipart/form-data" \
  -F "input=how much was spent according to the documents" \
  -F "files=@/path/to/file1.pdf" \
  -F "files=@/path/to/file2.xlsx"
```

`input` is optional if the agent is configured to process files directly.

**Example response with files/images**

```json
{
  "threadId": "681a191ad74ee8d89080289a",
  "content": "Here are the documents I found:\n- [file1_link]\n- [file2_link]",
  "images": ["image1_link", "image2_link"]
}
```

- `content` — Markdown links to generated files.
- `images` — Direct URLs to generated images.

## JSON Mode

If you enable JSON mode in the agent settings, the `content` field will return a full JSON object instead of Markdown.
