{"openapi":"3.1.0","info":{"title":"adTraces API","version":"1.0.0","description":"Implemented subset of the traces.com API (/v1/*) plus same-origin helpers."},"servers":[{"url":"https://adtraces.adfactory.app"}],"paths":{"/v1/namespaces":{"get":{"summary":"List namespaces of the caller","security":[{"bearerAuth":["namespace:read"]}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"post":{"summary":"Create an organization (device session only)","security":[{"bearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/NamespaceCreateRequest"}}}},"responses":{"201":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/namespaces/{slug}":{"get":{"summary":"Get a namespace","security":[{"bearerAuth":["namespace:read"]}],"parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/namespaces/{slug}/members":{"get":{"summary":"List members","security":[{"bearerAuth":["namespace:read"]}],"parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/namespaces/{slug}/traces":{"get":{"summary":"List traces of a namespace","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}},{"name":"limit","in":"query","required":false,"schema":{"type":"string"}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/namespaces/{slug}/invites":{"get":{"summary":"List invites (admins, device session)","security":[{"bearerAuth":["namespace:read"]}],"parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"post":{"summary":"Create an invite (admins, device session)","security":[{"bearerAuth":["namespace:read"]}],"parameters":[{"name":"slug","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InviteCreateRequest"}}}},"responses":{"201":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces":{"get":{"summary":"List traces in the active namespace","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"string"}},{"name":"gitRemoteUrl","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces/{externalId}":{"get":{"summary":"Get a trace","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"head":{"summary":"Check existence; returns Traces-Published-At header","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"put":{"summary":"Upsert trace metadata","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TraceUpsertRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"patch":{"summary":"Change trace metadata or visibility","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TraceUpsertRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"delete":{"summary":"Delete a trace","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces/{externalId}/transfer":{"post":{"summary":"Move a trace to another namespace","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransferRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces/{externalId}/messages":{"get":{"summary":"List messages","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"},{"name":"includeParts","in":"query","required":false,"schema":{"type":"string"}},{"name":"cursor","in":"query","required":false,"schema":{"type":"string"}},{"name":"limit","in":"query","required":false,"schema":{"type":"string"}},{"name":"filter","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces/{externalId}/messages/{messageId}":{"put":{"summary":"Upsert one message","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"},{"name":"messageId","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageUpsertRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/traces/{externalId}/messages/batch":{"post":{"summary":"Upsert up to 1000 messages (max 8 MiB)","security":[{"bearerAuth":["traces:write"]}],"parameters":[{"name":"externalId","in":"path","required":true,"schema":{"type":"string"},"description":"External id or internal id of the trace"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageBatchRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/session":{"get":{"summary":"Current session","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}},"delete":{"summary":"Log out (revokes a device session)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/session/switch":{"post":{"summary":"Switch the active namespace","security":[{"bearerAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionSwitchRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}},"/v1/auth/providers":{"get":{"summary":"Available login providers","security":[],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"404":{"description":"Not found"}}}},"/v1/auth/cli/start":{"post":{"summary":"Start a CLI device login","security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CliStartRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"404":{"description":"Not found"}}}},"/v1/auth/cli/status":{"get":{"summary":"Poll a CLI device login","security":[],"parameters":[{"name":"state","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"404":{"description":"Not found"}}}},"/v1/auth/cli/complete":{"post":{"summary":"Exchange an approved login for a device token","security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CliCompleteRequest"}}}},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"404":{"description":"Not found"}}}},"/api/v1/traces/{id}/download":{"get":{"summary":"Download a trace as jsonl or markdown","security":[{"bearerAuth":["traces:read"]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}},{"name":"format","in":"query","required":false,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"400":{"description":"Invalid request"},"401":{"description":"Missing or invalid token"},"403":{"description":"Missing scope or not a member"},"404":{"description":"Not found"}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"API key (trk_...) or CLI device token"}},"schemas":{"Envelope":{"oneOf":[{"type":"object","properties":{"ok":{"const":true},"data":{}},"required":["ok","data"]},{"type":"object","properties":{"ok":{"const":false},"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"},"details":{}},"required":["code","message"]}},"required":["ok","error"]}]},"TokenUsage":{"type":"object","properties":{"inputTokenCount":{"type":"number"},"outputTokenCount":{"type":"number"},"cacheReadTokenCount":{"type":"number"},"cacheWriteTokenCount":{"type":"number"},"reasoningTokenCount":{"type":"number"},"totalInputTokenCount":{"type":"number"}},"required":[]},"TraceUpsertRequest":{"type":"object","properties":{"agentId":{"type":"string"},"title":{"type":"string"},"projectPath":{"type":"string"},"projectName":{"type":"string"},"model":{"type":"string"},"tokenUsage":{"$ref":"#/components/schemas/TokenUsage"},"visibility":{"enum":["public","direct","private"]},"gitRemoteUrl":{"type":"string"},"gitBranch":{"type":"string"},"gitRef":{"type":"string"},"relatedTo":{"type":"string"},"relationshipType":{"enum":["subagent","resume"]},"sourceCreatedAt":{"type":"number"},"targetNamespaceId":{"type":"string"}},"required":[]},"Part":{"type":"object","properties":{"externalId":{"type":"string"},"sourceKey":{"type":"string"},"type":{"enum":["text","thinking","tool_call","tool_result","error","system_event"]},"content":{"type":"object"},"order":{"type":"number"},"tokenUsage":{"$ref":"#/components/schemas/TokenUsage"}},"required":["type","content","order"]},"MessageUpsertRequest":{"type":"object","properties":{"externalId":{"type":"string"},"idScheme":{"enum":["v1","v2"]},"sourceKey":{"type":"string"},"role":{"enum":["user","assistant","system"]},"textContent":{"type":"string"},"model":{"type":"string"},"order":{"type":"integer","minimum":0,"maximum":4294967295},"timestamp":{"type":"number"},"tokenUsage":{"$ref":"#/components/schemas/TokenUsage"},"parts":{"type":"array","items":{"$ref":"#/components/schemas/Part"}}},"required":["role"]},"MessageBatchRequest":{"type":"object","properties":{"idScheme":{"enum":["v1","v2"]},"messages":{"type":"array","minItems":1,"maxItems":1000,"items":{"$ref":"#/components/schemas/MessageUpsertRequest"}}},"required":["messages"]},"TransferRequest":{"type":"object","properties":{"targetNamespaceId":{"type":"string"}},"required":["targetNamespaceId"]},"SessionSwitchRequest":{"type":"object","properties":{"slug":{"type":"string"}},"required":["slug"]},"NamespaceCreateRequest":{"type":"object","properties":{"slug":{"type":"string"},"displayName":{"type":"string"},"description":{"type":"string"},"type":{"enum":["org"]},"billingEmail":{"type":"string"}},"required":["slug","displayName"]},"InviteCreateRequest":{"type":"object","properties":{"email":{"type":"string"},"maxUses":{"type":"integer","minimum":0},"expiryType":{"enum":["timed","never"]},"role":{"enum":["admin","member"]}},"required":[]},"CliStartRequest":{"type":"object","properties":{"provider":{"type":"string"},"deviceId":{"type":"string"},"deviceName":{"type":"string"},"devicePlatform":{"type":"string"},"deviceArchitecture":{"type":"string"},"namespaceId":{"type":"string"}},"required":[]},"CliCompleteRequest":{"type":"object","properties":{"state":{"type":"string"},"exchangeCode":{"type":"string"}},"required":["state","exchangeCode"]}}}}