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

> ## Agent Instructions
> Call https://api.feyn.ai only; the hosts behind it are not public.
> Authenticate with a workspace API key in the Authorization header: `Authorization: Bearer fn_...`. Keep keys server-side.
> For chat completions, use the official OpenAI SDK with base_url https://api.feyn.ai/v1 and a model ID from GET /v1/models.
> On 429, wait for the Retry-After header before retrying. Failed requests are not charged.

# Traces

> A trace is the full messages array of one model run, plus its output, cost, latency and status.

Write a trace with `POST /v1/traces`. Pick the project with the `X-Feyn-Project` header, using a key from [projects](https://docs.usefeyn.com/observability/projects.md).

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl https://api.feyn.ai/v1/traces \
  -H "Authorization: Bearer $FEYN_API_KEY" \
  -H "X-Feyn-Project: inbox-triage" \
  -H "Content-Type: application/json" \
  -d '{
    "traceKey": "run_123:decide",
    "messages": [
      { "role": "system", "content": "You triage email." },
      { "role": "user", "content": "Subject: Invoice overdue ..." },
      { "role": "assistant", "content": "notify" }
    ],
    "output": "notify",
    "latency": 491,
    "status": 200,
    "metadata": { "workflow_run_id": "wf_88" },
    "startedAt": 1726000000000,
    "completedAt": 1726000000491
  }'
```

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "id": "jd7..." }
```

## Fields

**traceKey** `string` *required*

Your id for this run. Writes with the same `traceKey` in the same project update one trace, so you can post when the request starts and again when it finishes, or safely retry.

**messages** `object[]` *required*

The conversation after the run: the request messages plus the completion, including tool turns. Store the messages, not a flattened prompt string.

**startedAt** `number` *required*

When the run started, in Unix milliseconds.

**completedAt** `number`

When the run finished, in Unix milliseconds.

**modelKey** `string`

The identifier of the model that produced the output.

**output** `string`

The last assistant text.

**reasoning** `string`

The last assistant reasoning, if the model returns it.

**cost** `number`

Cost of the run in USD.

**latency** `number`

Latency in milliseconds.

**status** `number`

The provider's HTTP status (`200`, `429`, `500`). Leave it out until the call finishes.

**metadata** `object`

Flat key-value pairs for filtering, such as run or customer ids. Values must be strings, numbers or booleans; they are stored as strings. Defaults to `{}`.

## Messages

| Field | Notes |
| - | - |
| `role` | `system`, `user`, `assistant` or `tool` |
| `content` | A string. Text content parts are joined into one string. May be empty on assistant tool-call turns |
| `reasoning` | Assistant only |
| `toolCalls` | Assistant only: `[{ id, name, arguments }]`, with `arguments` as a JSON string |
| `toolCallId` | Tool results only |
| `name` | The tool name, on tool results |

You can send tool calls in the shape your SDK already produces. OpenAI `tool_calls` (with a nested `function`) and AI SDK `{ type: "tool-call" }` content parts are both converted to `toolCalls`.

## Errors

`400` when a required field is missing, a role is unknown, `metadata` holds a non-scalar value, or `X-Feyn-Project` is missing. See [errors](https://docs.usefeyn.com/errors.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.