# Create Trace

Source: https://agenta.ai/docs/reference/api/create-trace

`POST /traces/`

Base URL: `https://us.cloud.agenta.ai/api` (US cloud), `https://eu.cloud.agenta.ai/api` (EU cloud) or `$AGENTA_HOST/api` (self-hosted). Authentication: `Authorization: ApiKey YOUR_API_KEY`.

Create a single trace from the canonical `Trace` shape.

Accepts one trace (`trace_id` plus a nested `spans` tree) and
returns the resulting `trace_id`. The payload is internally
normalized into the same ingest pipeline as
`POST /tracing/spans/ingest`.

Returns `202 Accepted`. The async write contract applies — see
[Tracing — Async write
contract](https://agenta.ai/docs/reference/api-guide/tracing.md#async-write-contract-202).

Use this when you want to operate on whole traces in the
list-shaped `Trace` payload. For flat-list ingestion or multiple
traces in one call, use `POST /traces/ingest` (plural).

## Request body schema

Content type: `application/json` (required)

- `trace` (object, nullable): A single trace record (trace_id plus nested spans). The `trace_id` must match the path parameter on edit endpoints.
  - `spans` (object, nullable)
  - `trace_id` (string, nullable)

## Response schemas

### 202: Successful Response

- `count` (integer): `1` if a `trace_id` was returned, `0` otherwise. Default: `0`.
- `trace_id` (string, nullable): 32-char hex UUID identifying the trace that was created or edited.

### 422: Validation Error

- `detail` (array of object)
  - `loc` (array of string | integer, required)
  - `msg` (string, required)
  - `type` (string, required)
  - `input` (any)
  - `ctx` (Context)
