> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://respan.ai/docs/apis/traces/delete-traces-in-bulk/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/_mcp/server. # Delete traces in bulk POST https://api.respan.ai/api/traces/bulk/ Content-Type: application/json Delete traces matching a non-empty filter object. The endpoint resolves at most 1,000 trace IDs per request; requests matching more are rejected with `422`. Use the query parameters for the canonical environment and time window; the same fields in the body only narrow that window. Only the documented filter fields and `metadata__` are supported. Unknown fields and invalid operators return `400` before anything is deleted. ClickHouse deletion is asynchronous, so `success_count` and `deleted_count` report traces submitted for deletion, not confirmation that every row has already disappeared. Rate limit: 10 requests per minute per organization and exact endpoint path for API-key calls (shared across API keys), and per user and exact endpoint path for JWT calls. Reference: https://respan.ai/docs/apis/traces/delete-traces-in-bulk ## Authentication - `Authorization` header (bearer token, required) — Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer \. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan\_params.credential\_override in the request body, not in this authentication field. - `Authorization` header (bearer token, required) — Use a dashboard JWT only for dashboard-authenticated endpoints. Respan API-key endpoints use the respanApiKey auth field instead. ## Request ### Query parameters - `start_time` (datetime, optional) — Start of time range (ISO 8601). Defaults to one hour before `end_time` when omitted. - `end_time` (datetime, optional) — End of time range (ISO 8601). Defaults to now when omitted. - `environment` (string, optional) — Filter by environment. ### Body (application/json) This endpoint expects an object. - `filters` (TraceBulkDeleteFilters, required) — Required. Selects the traces to delete. Each key is a field to filter on, and each value is a condition: `{"": {"operator": "", "value": [...]}}`. A trace must match every condition. To set two conditions on one field, such as a range, pass a list of conditions. **Operators:** `""` (equals, the default), `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains` (ignores case), `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `not_empty`. Put values in a list: `""` and `in` match any of the listed values, and `not` and `not_in` match none of them. Other operators take one value; for `empty` and `not_empty`, send `[""]`. **Fields:** `trace_unique_id`, `customer_identifier`, `environment`, `start_time`, `end_time`, `span_count`, `llm_call_count`, `error_count`, `total_cost`, `total_prompt_tokens`, `total_completion_tokens`, `total_tokens`, and `metadata__` (values are strings). Here `environment`, `start_time` and `end_time` only narrow the window set by the query parameters. Unsupported fields or operators return a 400 error, and nothing is deleted. **Example:** ```json { "trace_unique_id": {"operator": "in", "value": ["trace-01", "trace-02"]} } ``` ## Response ### 200 Traces were matched and submitted for asynchronous deletion. - `success_count` (integer, required) — Number of items successfully processed. - `error_count` (integer, required) — Number of items that failed. - `errors` (list of BulkItemError, required) — Item-level failures, keyed by zero-based input index. - `deleted_count` (integer, required) — Number of resources matched and processed for deletion. - `message` (string, required) — Human-readable deletion result. ## Errors ### 400 Bad Request Error The request body is missing `filters`, `filters` is empty, or it uses an unknown field or invalid operator. - `filters` (list of string, required) ### 403 Forbidden Error The API key is missing, invalid or expired, or it can't delete traces. - `detail` (string, required) ### 422 Unprocessable Entity Error The filters matched more than 1,000 traces. Narrow the filters and retry. - `detail` (string, required) ### 429 Too Many Requests Error Rate limit exceeded. - `detail` (string, required) - `retry_after` (integer, optional) — Seconds to wait before retrying. ### 500 Internal Server Error Internal Server Error - `error` (string, optional) ## Types ### TraceBulkDeleteFilters Required. Selects the traces to delete. Each key is a field to filter on, and each value is a condition: `{"": {"operator": "", "value": [...]}}`. A trace must match every condition. To set two conditions on one field, such as a range, pass a list of conditions. **Operators:** `""` (equals, the default), `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains` (ignores case), `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `not_empty`. Put values in a list: `""` and `in` match any of the listed values, and `not` and `not_in` match none of them. Other operators take one value; for `empty` and `not_empty`, send `[""]`. **Fields:** `trace_unique_id`, `customer_identifier`, `environment`, `start_time`, `end_time`, `span_count`, `llm_call_count`, `error_count`, `total_cost`, `total_prompt_tokens`, `total_completion_tokens`, `total_tokens`, and `metadata__` (values are strings). Here `environment`, `start_time` and `end_time` only narrow the window set by the query parameters. Unsupported fields or operators return a 400 error, and nothing is deleted. **Example:** ```json { "trace_unique_id": {"operator": "in", "value": ["trace-01", "trace-02"]} } ``` - `trace_unique_id` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `unique_organization_id` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `environment` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `start_time` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `end_time` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `span_count` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `llm_call_count` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `total_cost` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `total_prompt_tokens` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `total_completion_tokens` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `total_tokens` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `error_count` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `customer_identifier` (TraceFilterCondition, optional) — A trace filter condition. Use `is` for an exact value or `in` for any value in a list. ### BulkItemError An item that failed during a bulk operation. `index` is zero-based and identifies the corresponding item in the request array. - `index` (integer, required) — Zero-based index of the failed item in the submitted array. - `error` (string, required) — Error message for the failed item. ### TraceFilterCondition A trace filter condition. Use `is` for an exact value or `in` for any value in a list. - `value` (list of any, required) — One or more values used by the comparison. - `operator` (enum, optional, default: ) — Comparison operator. If omitted or empty, exact matching is used. - Allowed values: ``, `not`, `in`, `not_in`, `lt`, `lte`, `gt`, `gte`, `contains`, `not_contains`, `icontains`, `startswith`, `not_startswith`, `endswith`, `not_endswith`, `empty`, `notEmpty`, `not_empty`, `isnull` ## Examples ### Delete traces for one customer **Request** ```json { "filters": { "customer_identifier": { "value": [ "customer-123" ], "operator": "" } } } ``` **Response** ```json { "success_count": 42, "error_count": 0, "errors": [], "deleted_count": 42, "message": "Successfully deleted 42 traces" } ``` **SDK Code** ```python Delete traces for one customer import requests url = "https://api.respan.ai/api/traces/bulk/" querystring = {"start_time":"2025-01-01T00:00:00Z","end_time":"2025-01-31T23:59:59Z","environment":"prod"} payload = { "filters": { "customer_identifier": { "value": ["customer-123"], "operator": "" } } } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, params=querystring) print(response.json()) ``` ```javascript Delete traces for one customer const url = 'https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"filters":{"customer_identifier":{"value":["customer-123"],"operator":""}}}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Delete traces for one customer package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod" payload := strings.NewReader("{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby Delete traces for one customer require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}" response = http.request(request) puts response.read_body ``` ```java Delete traces for one customer import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}") .asString(); ``` ```php Delete traces for one customer request('POST', 'https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod', [ 'body' => '{ "filters": { "customer_identifier": { "value": [ "customer-123" ], "operator": "" } } }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Delete traces for one customer using RestSharp; var client = new RestClient("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Delete traces for one customer import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = ["filters": ["customer_identifier": [ "value": ["customer-123"], "operator": "" ]]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ### Delete selected trace IDs **Request** ```json { "filters": { "customer_identifier": { "value": [ "customer-123" ], "operator": "" } } } ``` **Response** ```json { "success_count": 42, "error_count": 0, "errors": [], "deleted_count": 42, "message": "Successfully deleted 42 traces" } ``` **SDK Code** ```python Delete selected trace IDs import requests url = "https://api.respan.ai/api/traces/bulk/" querystring = {"start_time":"2025-01-01T00:00:00Z","end_time":"2025-01-31T23:59:59Z","environment":"prod"} payload = { "filters": { "customer_identifier": { "value": ["customer-123"], "operator": "" } } } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers, params=querystring) print(response.json()) ``` ```javascript Delete selected trace IDs const url = 'https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"filters":{"customer_identifier":{"value":["customer-123"],"operator":""}}}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Delete selected trace IDs package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod" payload := strings.NewReader("{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby Delete selected trace IDs require 'uri' require 'net/http' url = URI("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}" response = http.request(request) puts response.read_body ``` ```java Delete selected trace IDs import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}") .asString(); ``` ```php Delete selected trace IDs request('POST', 'https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod', [ 'body' => '{ "filters": { "customer_identifier": { "value": [ "customer-123" ], "operator": "" } } }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Delete selected trace IDs using RestSharp; var client = new RestClient("https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"filters\": {\n \"customer_identifier\": {\n \"value\": [\n \"customer-123\"\n ],\n \"operator\": \"\"\n }\n }\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Delete selected trace IDs import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = ["filters": ["customer_identifier": [ "value": ["customer-123"], "operator": "" ]]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.respan.ai/api/traces/bulk/?start_time=2025-01-01T00%3A00%3A00Z&end_time=2025-01-31T23%3A59%3A59Z&environment=prod")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```