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.

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

FieldWhat it is
conversation_idRequired. Your id for this conversation.
user_messageRequired. The latest message from the person.
userYour id for the person. Set once: the first id wins and a different one later is refused.
organizationYour id for the company the person writes for, in B2B channels. Set once, like user.
contextAny object that helps the agent: customer data, the page, the plan. It can also feed the parameters of its tools.
attachmentsFiles sent with the message, such as images the agent should look at.
include_citationsKeep the knowledge base citations in the reply. Off by default.
tagsTags from your channel. They add up across messages.

Response

FieldWhat it is
eventsWhat the agent decided to do this turn, in order.
explanationWhere the conversation stands, in a sentence.
tool_callsThe calls the agent made to your systems.
collected_dataThe fields collected when a form inside the conversation is complete.
citationsThe knowledge base sources behind the reply, when asked for.
first_seenTrue on the first message of a conversation.
user_idThe person the conversation is bound to.
elapsed_time_msHow 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_typeWhat it is
messageA message for the person. Show it.
labelA label for the conversation.
priorityA priority for the conversation.
noteA private note for your team. Never show it to the person.
handoff_agentHand the conversation to a specific person on your team.
handoff_teamHand 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.

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}/conversations
A 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/batch
Full detail for up to 50 conversations in one request.
GET/projects/{project_id}/conversations/{conversation_id}/metrics
The quality scores of one conversation, once it has been scored.
GET/projects/{project_id}/conversations/analytics
Totals 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.

Job done

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