Bulk delete traces

Deletes multiple traces matching the given filters. Uses the same filter format as the [List Traces](/api-reference/observe/traces/list-traces) endpoint. Removes data from both raw span storage and the aggregated trace table. <Warning> The request body **must** contain a non-empty `filters` object. This prevents accidental deletion of all traces. Maximum **1,000 traces** per request — if the filter matches more, narrow your filters or use time-range pagination to delete in batches. </Warning> ## Query Parameters - `start_time` *string*: ISO 8601 start of time range. Defaults to `end_time` minus 1 hour. **Example** ```json "start_time": "2024-01-15T00:00:00Z" ``` - `end_time` *string*: ISO 8601 end of time range. Defaults to current time. **Example** ```json "end_time": "2024-01-15T23:59:59Z" ``` - `environment` *string*: Filter by environment (e.g., `production`, `staging`). ## Request Body - `filters` *object* **required**: Filter object to select traces for deletion. Must be non-empty. Uses the same format as the [List Traces](/api-reference/observe/traces/list-traces) endpoint. **Available filter fields:** - `trace_unique_id`, `customer_identifier`, `environment` - `span_count`, `llm_call_count`, `error_count` - `total_cost`, `total_tokens`, `total_prompt_tokens`, `total_completion_tokens` - Custom metadata: `metadata__your_field` See the [Filters API Reference](/api-reference/reference/filters-api-reference) for complete operators and format documentation. **Example** ```json { "filters": { "customer_identifier": { "operator": "=", "value": ["user@example.com"] } } } ``` ## Examples ```python Python url = "https://api.respan.ai/api/traces/bulk-delete/" headers = {"Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json"} params = { "start_time": "2024-01-15T00:00:00Z", "end_time": "2024-01-15T23:59:59Z" } # Delete all traces for a specific customer body = { "filters": { "customer_identifier": { "operator": "=", "value": ["user@example.com"] } } } response = requests.post(url, headers=headers, params=params, json=body) print(response.json()) ``` ```typescript TypeScript const url = "https://api.respan.ai/api/traces/bulk-delete/?start_time=2024-01-15T00:00:00Z&end_time=2024-01-15T23:59:59Z"; const response = await fetch(url, { method: "POST", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ filters: { customer_identifier: { operator: "=", value: ["user@example.com"], }, }, }), }); const data = await response.json(); console.log(data); ``` ```bash cURL curl -X POST "https://api.respan.ai/api/traces/bulk-delete/?start_time=2024-01-15T00:00:00Z&end_time=2024-01-15T23:59:59Z" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "filters": { "customer_identifier": { "operator": "=", "value": ["user@example.com"] } } }' ``` ### Delete specific traces by ID ```bash curl -X POST "https://api.respan.ai/api/traces/bulk-delete/" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "filters": { "trace_unique_id": { "operator": "IN", "value": ["trace_abc123", "trace_def456", "trace_ghi789"] } } }' ``` ### Delete traces with errors in a specific environment ```bash curl -X POST "https://api.respan.ai/api/traces/bulk-delete/?environment=staging" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "filters": { "error_count": { "operator": "gt", "value": [0] } } }' ``` ## Response ```json 200 OK { "deleted_count": 42, "message": "Successfully deleted 42 traces" } ``` ```json 200 No Matches { "deleted_count": 0, "message": "No traces matched the given filters" } ``` ```json 400 Too Many Matches { "error": "Filter matched more than 1000 traces. Narrow your filters or delete in smaller batches.", "matched_count": 1523 } ``` ```json 400 Missing Filters { "error": "Request body must contain a non-empty 'filters' list" } ``` ## Error Responses ```json 401 Unauthorized { "detail": "Your API key is invalid or expired, please check your API key at https://platform.respan.ai/platform/api/api-keys" } ```

Authentication

AuthorizationBearer
API key authentication. Get your API key from https://platform.respan.ai/platform/api-keys

Query parameters

start_timestringOptional

ISO 8601 start of time range. Defaults to end_time minus 1 hour.

end_timestringOptional
ISO 8601 end of time range. Defaults to current time.
environmentstringOptional

Filter by environment (e.g., production, staging).

Request

This endpoint expects an object.
filtersobjectRequired
Filter object to select traces for deletion. Must be non-empty. Uses the same format as the List Traces endpoint. Available filter fields: - trace_unique_id, customer_identifier, environment - span_count, llm_call_count, error_count - total_cost, total_tokens, total_prompt_tokens, total_completion_tokens - Custom metadata: metadata__your_field See the Filters API Reference for complete operators and format documentation.

Response

Successful response for Bulk delete traces
filtersobject

Errors

401
Unauthorized Error