---
title: "Foxford API: talk to your agents from your systems"
description: "How to call a Foxford agent from your own channel: API keys, the chat endpoint, its events, reading conversations, and the full OpenAPI reference."
url: https://foxford.ai/developers/api/
locale: en
translations: { es: https://foxford.ai/es/developers/api.md, pt: https://foxford.ai/pt/developers/api.md }
site: https://foxford.ai
---

Developers / API

# Talk to your agent from your systems

In the API an agent is a playbook. It has versions, and one of them is active: the one in production. Your channel sends it each message and does what the response says.

[Full reference](https://api.studiochat.io/docs)

## Chat with the active version

One endpoint: `POST /playbooks/{base_id}/active/chat`. The `base_id` stays the same across versions, so publishing a new version never changes your integration. If the agent has no active version, the endpoint answers `404`.

Use one `conversation_id` per conversation and send it on every turn. The agent keeps the state of the conversation on its side.

```
curl -X POST https://api.studiochat.io/playbooks/$AGENT_ID/active/chat \
 -H "X-API-Key: $FOXFORD_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{
 "conversation_id": "order-4821",
 "user_message": "Where is my order?",
 "user": "customer-1093"
 }'
```

### Request

| Field | What it is |
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
| conversation\_id | Required. Your id for this conversation. |
| user\_message | Required. The latest message from the person. |
| user | Your id for the person. Set once: the first id wins and a different one later is refused. |
| organization | Your id for the company the person writes for, in B2B channels. Set once, like user. |
| context | Any object that helps the agent: customer data, the page, the plan. It can also feed the parameters of its tools. |
| attachments | Files sent with the message, such as images the agent should look at. |
| include\_citations | Keep the knowledge base citations in the reply. Off by default. |
| tags | Tags from your channel. They add up across messages. |

### Response

| Field | What it is |
| ----------------- | --------------------------------------------------------------------- |
| events | What the agent decided to do this turn, in order. |
| explanation | Where the conversation stands, in a sentence. |
| tool\_calls | The calls the agent made to your systems. |
| collected\_data | The fields collected when a form inside the conversation is complete. |
| citations | The knowledge base sources behind the reply, when asked for. |
| first\_seen | True on the first message of a conversation. |
| user\_id | The person the conversation is bound to. |
| elapsed\_time\_ms | How long the reply took. |

The shape of a response, trimmed

```
{
 "events": [
 { "event_type": "message",
 "data": { "content": "It left the warehouse today. Here is the tracking link:..." } }
 ],
 "explanation": "Order found, shipping status shared.",
 "tool_calls": [... ],
 "first_seen": true,
 "user_id": "customer-1093",
 "elapsed_time_ms": 2140
}
```

### Events

| event\_type | What it is |
| -------------- | ---------------------------------------------------------- |
| message | A message for the person. Show it. |
| label | A label for the conversation. |
| priority | A priority for the conversation. |
| note | A private note for your team. Never show it to the person. |
| handoff\_agent | Hand the conversation to a specific person on your team. |
| handoff\_team | Hand the conversation to a team. |

## Keys

Every request carries a project key in the `X-API-Key` header. Keys belong to one project, can be rotated, and are shown once, when they are created. Your Foxford team issues them.

A sandbox key starts with `sbs_`. With it, a request that would change something returns `202` and an `approval_id` instead of running: a person approves it first.

A request without a key gets a `401`. Errors come back as JSON with a `detail` field.

Response without a key

```
HTTP/1.1 401 Unauthorized
{"detail": "No authorization provided"}
```

## Read conversations

Every conversation that runs through an agent can be read back with the same key: the messages, the tools it called, the sources it cited and how it was scored.

| GET | /projects/{project\_id}/conversationsA page of conversations. Filter by dates, version, handoff, sentiment or your user id. Up to 100 per page. |
| ---- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| GET | /projects/{project\_id}/conversations/{conversation\_id}One conversation: every message, tool call and citation. |
| POST | /projects/{project\_id}/conversations/batchFull detail for up to 50 conversations in one request. |
| GET | /projects/{project\_id}/conversations/{conversation\_id}/metricsThe quality scores of one conversation, once it has been scored. |
| GET | /projects/{project\_id}/conversations/analyticsTotals for a period: volume, what was resolved without a person, by version and by tag. |

```
# the last 100 conversations that were handed to a person
curl "https://api.studiochat.io/projects/$PROJECT_ID/conversations?has_handoff=true&limit=100" \
 -H "X-API-Key: $FOXFORD_API_KEY"

# full detail for up to 50 at once
curl -X POST "https://api.studiochat.io/projects/$PROJECT_ID/conversations/batch" \
 -H "X-API-Key: $FOXFORD_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{ "conversation_ids": ["order-4821", "order-4822"] }'
```

## The full reference

Every endpoint, with its schemas, is in the OpenAPI document generated from the code. Your key reaches the endpoints of its own project.

[Swagger UI](https://api.studiochat.io/docs) [ReDoc](https://api.studiochat.io/redoc) [openapi.json](https://api.studiochat.io/openapi.json)

Job done

Tell us which task comes off the list first. We start by mapping it with you.

[Book a demo](https://cal.foxford.ai/sales)
