# API Documentation - `https://app.andara.ai/api/andara/agent`

## Overview
This endpoint forwards a user prompt to the **Andara AI** agent. It streams back a conversation using Server-Sent Events (SSE).

| Feature | Description |
|---------|-------------|
| Method  | `POST` |

## Request

### URL
```
https://app.andara.ai/api/andara/agent
```

### Headers
- `Content-Type: application/json` - required.
- `x-api-key: ANDARA_AI_API_KEY` - your Andara AI API key for authentication.

### Body Schema
```json
{
  "messages": { "messages":[
    {
      "role": "user" | "assistant" | "system",
      "content": "<text>"
    },
    ...
  ]}
}
```
- `messages` must have key `messages` with an array of message objects. The first messages object is typically a user prompt.

### Example (curl)
```bash
curl -X POST https://app.andara.ai/api/andara/agent \
  -H "Content-Type: application/json" \
  -H "x-api-key: ANDARA_AI_API_KEY" \
  --data-raw '{"messages":{"messages":[{"role":"user","content":"Explain the Balanced Scorecard in simple terms."}]}}' \
  -N
```
The `-N` flag tells curl to not buffer output, which is useful for streaming SSE.

## Response
The API streams a **Server‑Sent Events (SSE)** payload. Each event contains either incremental content or tool call arguments.

```text
data: {"delta":{"content":"Here is the respons"}}

# ... more events ...

data: [DONE]
```
The client should parse each line starting with `data:` and accumulate the JSON object under `delta`. When a line contains `[DONE]`, the stream ends.

### HTTP Status Codes
| Code | Meaning |
|------|---------|
| 200  | Success - SSE stream begins. |
| 400  | Bad request - missing/invalid body or headers. |
| 401  | Unauthorized - invalid or missing `x-api-key`. |
| 500  | Internal Server Error - the server failed to process the request. |

## Error Response (JSON)
In case of non‑streaming errors, a JSON payload is returned:
```json
{
  "error": "Internal Server Error"
}
```
The HTTP status will be `500`.

## Notes
- Because SSE is used, clients should handle reconnection logic if needed.
