{"openapi":"3.1.0","info":{"title":"CrbonFree API","version":"1.0.0","description":"Track AI workload carbon emissions: ingest provider telemetry, calculate per-tier CO₂ with versioned factors, generate signed retirement receipts.","contact":{"name":"CrbonFree","url":"https://crbonfree.com"}},"servers":[{"url":"https://api.crbonfree.com","description":"Production"}],"tags":[{"name":"Projects","description":"Workspace organization for telemetry"},{"name":"Usage","description":"Token/cost/carbon aggregates + water-footprint estimate (AIW-290)"},{"name":"Telemetry","description":"Event-level telemetry + emissions detail"},{"name":"Factors","description":"Versioned emissions factor sets behind every calculation (read-only, AIW-9)"},{"name":"Billing","description":"Receipts, audit packs, overage, periods, plan tier"},{"name":"Partner","description":"For AI gateways: send your customers’ usage and read back CO2e, energy and water. Beta, partner keys only."}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"Clerk-issued session JWT, sent as `Authorization: Bearer <token>`. Obtain it via `clerk.session.getToken()` in the browser SDK."},"apiKey":{"type":"apiKey","in":"header","name":"X-API-Key","description":"Long-lived API key issued via POST /api/v1/api-keys. Format: ck_live_<32 chars base64url>. Sent in the X-API-Key header (NOT in Authorization — that header is reserved for the Clerk JWT path)."},"partnerKey":{"type":"http","scheme":"bearer","description":"A partner key, sent as `Authorization: Bearer <key>`. A test key is `cp_test_` and a live key is `cp_live_`, each followed by 32 characters (letters, digits, `_` and `-`). Test and live data are kept apart: a test key reads only test data, and a live key only live data. Crbon Labs creates each partner account and issues its keys. There is no sign-up. Only the partner routes accept a partner key."}},"schemas":{"PartnerUsageCounts":{"type":["object","null"],"properties":{"input_tokens":{"type":["integer","null"],"minimum":0,"maximum":10000000000,"description":"Input tokens, not counting cached or cache-write tokens. A whole number from 0 to 10,000,000,000. Missing or null means 0.","example":400},"cached_input_tokens":{"type":["integer","null"],"minimum":0,"maximum":10000000000,"description":"Input tokens read from the prompt cache. A whole number from 0 to 10,000,000,000. Missing or null means 0.","example":800},"cache_write_tokens":{"type":["integer","null"],"minimum":0,"maximum":10000000000,"description":"Input tokens written to the prompt cache. A whole number from 0 to 10,000,000,000. Missing or null means 0.","example":0},"output_tokens":{"type":["integer","null"],"minimum":0,"maximum":10000000000,"description":"Output tokens, not counting reasoning tokens. A whole number from 0 to 10,000,000,000. Missing or null means 0.","example":230},"reasoning_tokens":{"type":["integer","null"],"minimum":0,"maximum":10000000000,"description":"Reasoning tokens. They are counted as output tokens. A whole number from 0 to 10,000,000,000. Missing or null means 0.","example":120}},"additionalProperties":false,"description":"The token counts of the request. The five counts do not overlap: each token is in exactly one of them. For a text request, at least one count must be above 0, or the event is invalid with reason no_usage. Missing or null means every count is 0. Any other field here refuses the whole call."},"PartnerUsageEvent":{"type":"object","properties":{"id":{"type":"string","minLength":1,"maxLength":128,"description":"Your own ID for this request: 1 to 128 characters, with no control characters. We use it to spot a resend: an event sent again with the same ID is not counted twice.","example":"req_01HZX"},"occurred_at":{"type":"string","description":"When the request ran: an RFC 3339 date and time with a time zone, such as 2026-11-10T16:04:11Z or 2026-11-10T10:04:11-06:00. It is stored in UTC, to the millisecond. A new event must be at most 5 minutes ahead of our clock and at most 90 days old, or it is invalid with reason occurred_at_out_of_range. An event we already hold is matched by its ID whatever its age.","example":"2026-11-10T16:04:11Z"},"customer_id":{"type":"string","pattern":"^[A-Za-z0-9._:@-]{1,128}$","description":"Your own ID for the customer who made the request, such as their account ID in your system: 1 to 128 characters of A-Z a-z 0-9 . _ : @ -. Totals can be read for one customer by this ID. Do not send a name or an email address.","example":"acct_8f2c"},"model":{"type":"string","minLength":1,"maxLength":256,"description":"The model that really served the request, as your gateway names it: 1 to 256 characters. One prefix before a slash, such as anthropic/, is ignored when we match the model. A model we have no factor for is stored as not_covered.","example":"anthropic/claude-sonnet-5"},"provider":{"type":["string","null"],"minLength":1,"maxLength":100,"description":"Optional: the provider that served the request, 1 to 100 characters. We store it as sent, and it does not change the figures.","example":"anthropic"},"region":{"type":["string","null"],"minLength":1,"maxLength":100,"description":"Optional: the region that served the request, 1 to 100 characters. We store it as sent, and it does not change the figures.","example":"us-east-1"},"modality":{"type":["string","null"],"enum":["text","image","video","speech",null],"description":"Optional: text (the default), image, video or speech. Only text is estimated: any other modality is stored as not_covered with reason unsupported_modality.","example":"text"},"usage":{"$ref":"#/components/schemas/PartnerUsageCounts"},"cost_usd":{"type":["string","null"],"description":"Optional: what the request cost, in US dollars, as a decimal string with at most 15 digits before the point and 9 after. We store it as given. We do not compute it, and it does not change the figures.","example":"0.0123"}},"required":["id","occurred_at","customer_id","model"],"additionalProperties":false,"description":"One request your gateway served. A field not listed here refuses the whole call with 400, which is also what keeps prompt and reply text out. An optional field sent as null is the same as leaving it out."},"PartnerUsageEventsRequest":{"type":"object","properties":{"events":{"type":"array","items":{"$ref":"#/components/schemas/PartnerUsageEvent"},"minItems":1,"maxItems":1000,"description":"1 to 1,000 events. Each gets one result, in the order sent."}},"required":["events"],"additionalProperties":false,"description":"The body of a call: { \"events\": [ ... ] }, at most 2 MB. Any other field refuses the whole call."},"ErrorResponse":{"type":"object","properties":{"success":{"type":"boolean","enum":[false]},"error":{"type":"string","example":"INSUFFICIENT_PERMISSIONS"},"message":{"type":"string","example":"Insufficient permissions for this organization"},"upgradeUrl":{"type":"string","example":"/billing"},"details":{"type":"object","additionalProperties":{}}},"required":["success","error","message"]},"ProjectPublic":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string","example":"Default"},"isDefault":{"type":"boolean"},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","name","isDefault","createdAt","updatedAt"]},"ProjectWithUsage":{"allOf":[{"$ref":"#/components/schemas/ProjectPublic"},{"type":"object","properties":{"connectionCount":{"type":"integer","minimum":0},"last30dCo2Kg":{"type":"number","minimum":0}},"required":["connectionCount","last30dCo2Kg"]}]},"CostCoverage":{"type":"object","properties":{"reportedEvents":{"type":"integer","minimum":0,"description":"Events in the scope that carry a provider-reported cost (a reported $0 counts)."},"totalEvents":{"type":"integer","minimum":0,"description":"Every event in the scope."}},"required":["reportedEvents","totalEvents"],"description":"Provider-cost coverage of the cost next to it. Cost comes only from the provider; sources that report none (for example Bedrock, Microsoft 365 Copilot, coding agents) leave it unset. When `reportedEvents` is 0 the cost was not reported, which is not the same as $0; when it is below `totalEvents` the cost covers only those events."},"UsageSummary":{"type":"object","properties":{"range":{"type":"object","properties":{"start":{"type":"string"},"end":{"type":"string"}},"required":["start","end"]},"totals":{"type":"object","properties":{"totalTokens":{"type":"number"},"promptTokens":{"type":"number"},"completionTokens":{"type":"number"},"totalCostUsd":{"type":"number"},"requestCount":{"type":"number"},"carbonKg":{"type":"number"},"electricityKwh":{"type":"number"},"waterLiters":{"type":"number","description":"Estimated water footprint in liters (on-site cooling + off-site generation). ESTIMATE ONLY — never part of the signed Footprint Statement, receipts, or audit packs."},"waterLowerBoundL":{"type":"number","description":"Lower uncertainty bound of the water estimate (liters, ~±50% band)."},"waterUpperBoundL":{"type":"number","description":"Upper uncertainty bound of the water estimate (liters, ~±50% band)."},"offsetCostUsd":{"type":["number","null"],"description":"Deprecated. Returns null after the AIW-13 pricing cutover.","deprecated":true},"costCoverage":{"$ref":"#/components/schemas/CostCoverage"}},"required":["totalTokens","promptTokens","completionTokens","totalCostUsd","requestCount","carbonKg","electricityKwh","waterLiters","waterLowerBoundL","waterUpperBoundL","offsetCostUsd","costCoverage"]},"chart":{"type":"object","properties":{"labels":{"type":"array","items":{"type":"string"}},"datasets":{"type":"array","items":{"type":"object","properties":{"label":{"type":"string"},"data":{"type":"array","items":{"type":"number"}}},"required":["label","data"]},"description":"One series per metric, each with one value per entry in `labels`, in this order: \"Tokens\", \"Cost (USD)\", \"Electricity (kWh)\", \"Carbon (kg CO2)\", \"Water (L)\". Match a series by its `label`. \"Water (L)\" is the estimated water footprint in liters per day. ESTIMATE ONLY — never part of the signed Footprint Statement, receipts, or audit packs."},"costCoverage":{"type":"array","items":{"$ref":"#/components/schemas/CostCoverage"},"description":"Provider-cost coverage of the \"Cost (USD)\" series, one entry per entry in `labels`."}},"required":["labels","datasets","costCoverage"]}},"required":["range","totals","chart"]},"UsageBreakdownItem":{"type":"object","properties":{"model":{"type":"string"},"promptTokens":{"type":"number"},"completionTokens":{"type":"number"},"totalTokens":{"type":"number"},"requestCount":{"type":"number"},"costUsd":{"type":"number"},"percentage":{"type":"number"},"carbonKg":{"type":"number"},"offsetCostUsd":{"type":["number","null"],"description":"Deprecated. Returns null after the AIW-13 pricing cutover.","deprecated":true},"electricityKwh":{"type":"number"},"costCoverage":{"$ref":"#/components/schemas/CostCoverage"}},"required":["model","promptTokens","completionTokens","totalTokens","requestCount","costUsd","percentage","carbonKg","offsetCostUsd","electricityKwh","costCoverage"]},"DailyUsageRow":{"type":"object","properties":{"date":{"type":"string"},"projectName":{"type":"string"},"promptTokens":{"type":"number"},"completionTokens":{"type":"number"},"totalTokens":{"type":"number"},"requestCount":{"type":"number"},"costUsd":{"type":"number"},"carbonKg":{"type":"number"},"energyKwh":{"type":"number"},"waterLiters":{"type":"number","description":"Estimated water footprint in liters for the day. ESTIMATE ONLY — never part of the signed Footprint Statement, receipts, or audit packs."},"costCoverage":{"$ref":"#/components/schemas/CostCoverage"}},"required":["date","promptTokens","completionTokens","totalTokens","requestCount","costUsd","carbonKg","energyKwh","waterLiters","costCoverage"]},"DailyUsageExportRow":{"type":"object","properties":{"date":{"type":"string"},"project_name":{"type":"string"},"prompt_tokens":{"type":"number"},"completion_tokens":{"type":"number"},"total_tokens":{"type":"number"},"request_count":{"type":"number"},"cost_usd":{"type":"number"},"carbon_kg":{"type":"number"},"energy_kwh":{"type":"number"}},"required":["date","project_name","prompt_tokens","completion_tokens","total_tokens","request_count","cost_usd","carbon_kg","energy_kwh"]},"UsageExportFullRow":{"type":"object","properties":{"date":{"type":"string"},"model":{"type":"string"},"provider":{"type":"string","description":"The connection's provider."},"connection_id":{"type":"string","format":"uuid"},"connection_type":{"type":"string","enum":["api","oauth","agent","browser"]},"project_id":{"type":"string","format":"uuid"},"project_name":{"type":"string"},"person_key":{"type":["string","null"],"description":"`user:<uuid>`, `email:<address>` (a Microsoft 365 user who is not a member) or `unattributed`. An admin's export covers every person; anyone else's covers only their own usage. Null for API-key callers, whose rows are not split by person."},"person_name":{"type":["string","null"],"description":"The member's name; empty for email and unattributed rows. Never an email. Null for API-key callers."},"input_tokens_uncached":{"type":"integer","minimum":0},"input_tokens_cached":{"type":"integer","minimum":0},"input_tokens_cache_creation":{"type":"integer","minimum":0},"output_tokens":{"type":"integer","minimum":0},"total_tokens":{"type":"integer","minimum":0},"request_count":{"type":"integer","minimum":0},"provider_cost_usd":{"type":["number","null"],"description":"Provider-reported cost; null (an empty CSV cell) when no event in the row reported one. Not reported is not $0."},"cost_reported_events":{"type":"integer","minimum":0},"total_events":{"type":"integer","minimum":0},"carbon_kg":{"type":"number"},"energy_kwh":{"type":"number"},"water_liters":{"type":"number","description":"Estimated water footprint in liters. ESTIMATE ONLY."}},"required":["date","model","provider","connection_id","connection_type","project_id","project_name","person_key","person_name","input_tokens_uncached","input_tokens_cached","input_tokens_cache_creation","output_tokens","total_tokens","request_count","provider_cost_usd","cost_reported_events","total_events","carbon_kg","energy_kwh","water_liters"]},"PaginationMeta":{"type":"object","properties":{"page":{"type":"integer","minimum":0},"limit":{"type":"integer","exclusiveMinimum":0},"total":{"type":"integer","minimum":0},"totalPages":{"type":"integer","minimum":0}},"required":["page","limit","total","totalPages"]},"TelemetrySummary":{"type":"object","properties":{"total_co2_kg":{"type":"number"},"total_co2_lower_bound_kg":{"type":"number"},"total_co2_upper_bound_kg":{"type":"number"},"total_tokens":{"type":"number"},"cached_vs_uncached":{"type":"object","properties":{"uncached_tokens":{"type":"number"},"cached_tokens":{"type":"number"},"cache_creation_tokens":{"type":"number"},"cached_co2_savings_kg":{"type":"number"}},"required":["uncached_tokens","cached_tokens","cache_creation_tokens","cached_co2_savings_kg"]},"per_model":{"type":"array","items":{"type":"object","properties":{"model":{"type":"string"},"total_tokens":{"type":"number"},"co2_kg":{"type":"number"},"percentage":{"type":"number"}},"required":["model","total_tokens","co2_kg","percentage"]}},"daily_chart":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string"},"co2_kg":{"type":"number"},"tokens":{"type":"number"}},"required":["date","co2_kg","tokens"]}},"factors_version":{"type":"string"},"period":{"type":"object","properties":{"start":{"type":"string"},"end":{"type":"string"}},"required":["start","end"]}},"required":["total_co2_kg","total_co2_lower_bound_kg","total_co2_upper_bound_kg","total_tokens","cached_vs_uncached","per_model","daily_chart","factors_version","period"]},"TelemetryModel":{"type":"object","properties":{"provider":{"type":"string"},"model":{"type":"string"},"total_tokens":{"type":"number"},"total_co2_kg":{"type":"number"},"event_count":{"type":"integer"},"first_seen":{"type":"string"},"last_seen":{"type":"string"}},"required":["provider","model","total_tokens","total_co2_kg","event_count","first_seen","last_seen"]},"BillingPeriod":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"periodStart":{"type":"string","format":"date-time"},"periodEnd":{"type":"string","format":"date-time"},"status":{"type":"string","enum":["open","reconciling","ready","closing","closed","failed"]},"totals":{"type":"object","properties":{"inputTokensUncached":{"type":"string"},"inputTokensCached":{"type":"string"},"inputTokensCacheCreation":{"type":"string"},"outputTokens":{"type":"string"},"requestCount":{"type":"string"},"providerCostUsd":{"type":"number"},"carbonKg":{"type":"number"},"electricityKwh":{"type":"number"}},"required":["inputTokensUncached","inputTokensCached","inputTokensCacheCreation","outputTokens","requestCount","providerCostUsd","carbonKg","electricityKwh"]},"factorsVersions":{"type":"array","items":{"type":"string"}},"planTierAtClose":{"type":["string","null"],"enum":["free","starter","growth","scale","enterprise","payg"]},"closedAt":{"type":["string","null"],"format":"date-time"},"createdAt":{"type":"string","format":"date-time"},"stripeInvoiceId":{"type":["string","null"]},"amountChargedCents":{"type":["integer","null"]},"failureReason":{"type":["string","null"],"enum":["payment_failed","aggregation_failed","signing_failed"]},"paidAt":{"type":["string","null"],"format":"date-time"},"readyAt":{"type":["string","null"],"format":"date-time"},"closingAt":{"type":["string","null"],"format":"date-time"},"carbonReceiptId":{"type":["string","null"],"format":"uuid"},"statementId":{"type":["string","null"],"format":"uuid"},"statementStatus":{"type":["string","null"],"enum":["pending","signing","signed","failed","unavailable"]}},"required":["id","periodStart","periodEnd","status","totals","factorsVersions","planTierAtClose","closedAt","createdAt","stripeInvoiceId","amountChargedCents","failureReason","paidAt","readyAt","closingAt","carbonReceiptId","statementId","statementStatus"]},"RetirementStatus":{"type":"object","properties":{"periodId":{"type":"string","format":"uuid"},"periodStart":{"type":"string","format":"date-time"},"periodEnd":{"type":"string","format":"date-time"},"status":{"type":"string","enum":["collecting","calculating","awaiting_payment","retiring","retired","pending_signature","action_required"]},"carbonKg":{"type":"number"},"electricityKwh":{"type":"number"},"amountChargedCents":{"type":["integer","null"]},"paidAt":{"type":["string","null"],"format":"date-time"},"closedAt":{"type":["string","null"],"format":"date-time"},"receipt":{"type":["object","null"],"properties":{"id":{"type":"string","format":"uuid"},"co2Kg":{"type":"number"},"isSigned":{"type":"boolean"},"verificationUrl":{"type":"string"},"pdfUrl":{"type":["string","null"]},"signedAt":{"type":["string","null"],"format":"date-time"}},"required":["id","co2Kg","isSigned","verificationUrl","pdfUrl","signedAt"]}},"required":["periodId","periodStart","periodEnd","status","carbonKg","electricityKwh","amountChargedCents","paidAt","closedAt","receipt"]},"ReceiptListEntry":{"allOf":[{"$ref":"#/components/schemas/BillingPeriod"},{"type":"object","properties":{"receipt":{"type":["object","null"],"properties":{"id":{"type":"string","format":"uuid"},"co2Kg":{"type":"number"},"serialAllocations":{"type":"array","items":{"type":"object","properties":{"serialNumber":{"type":"string"},"totalKgCo2e":{"type":"number"}},"required":["serialNumber","totalKgCo2e"]}},"verificationUrl":{"type":"string"},"previewUrl":{"type":["string","null"]},"pdfUrl":{"type":["string","null"]},"isSigned":{"type":"boolean"},"signedAt":{"type":["string","null"],"format":"date-time"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","co2Kg","serialAllocations","verificationUrl","previewUrl","pdfUrl","isSigned","signedAt","createdAt"]}},"required":["receipt"]}]},"CarbonReceipt":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"billingPeriodId":{"type":["string","null"],"format":"uuid"},"co2Kg":{"type":"number"},"serialAllocations":{"type":"array","items":{"type":"object","properties":{"serialNumber":{"type":"string"},"totalKgCo2e":{"type":"number"}},"required":["serialNumber","totalKgCo2e"]}},"verificationUrl":{"type":"string"},"previewUrl":{"type":["string","null"]},"pdfUrl":{"type":["string","null"]},"isSigned":{"type":"boolean"},"statementId":{"type":["string","null"],"format":"uuid"},"signedAt":{"type":["string","null"],"format":"date-time"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","billingPeriodId","co2Kg","serialAllocations","verificationUrl","previewUrl","pdfUrl","isSigned","statementId","signedAt","createdAt"]},"TrustSignedStatement":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"billingPeriodId":{"type":["string","null"],"format":"uuid"},"artifactType":{"type":"string","enum":["footprint_statement"]},"statementVersion":{"type":"integer","exclusiveMinimum":0},"status":{"type":"string","enum":["pending","signing","signed","failed","unavailable"]},"period":{"type":"object","properties":{"start":{"type":"string","format":"date-time"},"end":{"type":"string","format":"date-time"}},"required":["start","end"]},"usage":{"type":"object","additionalProperties":{"type":"string"}},"footprint":{"type":"object","additionalProperties":{"type":"string"}},"methodology":{"type":"object","properties":{"factorVersions":{"type":"array","items":{"type":"string"}},"waterFactorVersions":{"type":"array","items":{"type":"string"}},"layers":{"type":["object","null"],"additionalProperties":{}}},"required":["factorVersions","waterFactorVersions","layers"]},"statementUrl":{"type":["string","null"],"format":"uri"},"verificationUrl":{"type":["string","null"],"format":"uri"},"signedAt":{"type":["string","null"],"format":"date-time"},"createdAt":{"type":"string","format":"date-time"},"supersededByStatementId":{"type":["string","null"],"format":"uuid"}},"required":["id","billingPeriodId","artifactType","statementVersion","status","period","usage","footprint","methodology","statementUrl","verificationUrl","signedAt","createdAt","supersededByStatementId"]},"AuditPack":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"organizationId":{"type":"string","format":"uuid"},"packYear":{"type":"integer"},"packMonth":{"type":"integer","minimum":1,"maximum":12},"periodStart":{"type":"string","format":"date-time"},"periodEnd":{"type":"string","format":"date-time"},"blobUrl":{"type":"string"},"manifestHash":{"type":"string"},"receiptCount":{"type":"integer","minimum":0},"fileCount":{"type":"integer","minimum":0},"totalBytes":{"type":"integer","minimum":0},"generatedAt":{"type":"string","format":"date-time"},"createdAt":{"type":"string","format":"date-time"}},"required":["id","organizationId","packYear","packMonth","periodStart","periodEnd","blobUrl","manifestHash","receiptCount","fileCount","totalBytes","generatedAt","createdAt"]},"CarbonFactorVersionSummary":{"type":"object","properties":{"version":{"type":"string","example":"v1.2"},"active":{"type":"boolean"},"layered":{"type":"boolean"},"tierCount":{"type":"integer"},"createdAt":{"type":"string"}},"required":["version","active","layered","tierCount","createdAt"]},"CarbonFactorVersionList":{"type":"object","properties":{"versions":{"type":"array","items":{"$ref":"#/components/schemas/CarbonFactorVersionSummary"}}},"required":["versions"]},"CarbonFactor":{"type":"object","properties":{"version":{"type":"string","example":"v1.2"},"modelTier":{"type":"string","example":"medium"},"modelPatterns":{"type":"array","items":{"type":"string"},"description":"Case-insensitive glob patterns; first match wins, most specific tier first. A leading `vendor/` segment is stripped from the model id before matching (`openai/gpt-4o-mini` matches as `gpt-4o-mini`); an `arn:` id is matched whole."},"energyPerTokenPrefillJ":{"type":"number"},"energyPerTokenDecodeJ":{"type":"number"},"energyPerTokenCachedJ":{"type":"number"},"pue":{"type":"number"},"gridIntensityKgPerKwh":{"type":"number"},"uncertaintyPct":{"type":"number"},"wueLPerKwh":{"type":"number","description":"Water-use effectiveness; 0 on carbon-only v1.0 rows."},"gridWaterLPerKwh":{"type":"number"},"waterUncertaintyPct":{"type":"number"},"hostPowerFactor":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"clusterUtilization":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"embodiedKgPerMtok":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"trainingKgPerMtok":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"activityUncertaintyPct":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"emissionFactorUncertaintyPct":{"type":["number","null"],"description":"v1.2 layered-emissions factor; null on legacy v1.0/v1.1 rows."},"createdAt":{"type":"string","description":"ISO-8601; when the version was seeded."}},"required":["version","modelTier","modelPatterns","energyPerTokenPrefillJ","energyPerTokenDecodeJ","energyPerTokenCachedJ","pue","gridIntensityKgPerKwh","uncertaintyPct","wueLPerKwh","gridWaterLPerKwh","waterUncertaintyPct","hostPowerFactor","clusterUtilization","embodiedKgPerMtok","trainingKgPerMtok","activityUncertaintyPct","emissionFactorUncertaintyPct","createdAt"]},"CarbonFactorSet":{"type":"object","properties":{"version":{"type":"string","example":"v1.2"},"active":{"type":"boolean","description":"True when this is the version the pipeline currently writes with."},"layered":{"type":"boolean","description":"True when the version carries the v1.2 layered-emissions factors."},"factors":{"type":"array","items":{"$ref":"#/components/schemas/CarbonFactor"}}},"required":["version","active","layered","factors"]},"PublicTotalTokens":{"type":"object","properties":{"totalTokens":{"type":"number","description":"Cumulative tokens tracked across all organizations, all time.","example":1284930571}},"required":["totalTokens"]},"PublicEmissionsEstimate":{"type":"object","properties":{"energyJoules":{"type":"number"},"energyKwh":{"type":"number"},"co2Kg":{"type":"number"},"co2LowerBoundKg":{"type":"number"},"co2UpperBoundKg":{"type":"number"},"waterLiters":{"type":"number"},"waterLowerBoundL":{"type":"number"},"waterUpperBoundL":{"type":"number"},"waterFactorsVersion":{"type":"string"},"modelTier":{"type":"string"},"pue":{"type":"number"},"gridIntensity":{"type":"number"},"uncertaintyPct":{"type":"number"},"factorsVersion":{"type":"string"}},"required":["energyJoules","energyKwh","co2Kg","co2LowerBoundKg","co2UpperBoundKg","waterLiters","waterLowerBoundL","waterUpperBoundL","waterFactorsVersion","modelTier","pue","gridIntensity","uncertaintyPct","factorsVersion"]},"PublicEmissionsEstimateRequest":{"type":"object","properties":{"model":{"type":"string","minLength":1,"maxLength":200,"description":"Model id matched against carbon_factors exactly like the worker ingestion path.","example":"gpt-4o-mini"},"inputTokensUncached":{"type":"integer","minimum":0,"default":0,"example":1000},"inputTokensCached":{"type":"integer","minimum":0,"default":0,"example":0},"inputTokensCacheCreation":{"type":"integer","minimum":0,"default":0,"example":0},"outputTokens":{"type":"integer","minimum":0,"default":0,"example":500}},"required":["model"]},"PublicShowcaseUsage":{"type":"object","properties":{"range":{"type":"object","properties":{"start":{"type":"string"},"end":{"type":"string"}},"required":["start","end"]},"totals":{"type":"object","properties":{"totalTokens":{"type":"number"},"inputTokens":{"type":"number","description":"Uncached + cached + cache-creation input tokens."},"outputTokens":{"type":"number"},"requestCount":{"type":"number"},"carbonKg":{"type":"number"},"electricityKwh":{"type":"number"},"waterLiters":{"type":"number","description":"Estimated water footprint in liters. ESTIMATE ONLY."},"waterLowerBoundL":{"type":"number","description":"Lower uncertainty bound of the water estimate (liters)."},"waterUpperBoundL":{"type":"number","description":"Upper uncertainty bound of the water estimate (liters)."}},"required":["totalTokens","inputTokens","outputTokens","requestCount","carbonKg","electricityKwh","waterLiters","waterLowerBoundL","waterUpperBoundL"]},"avgDailyTokens":{"type":"number","description":"totalTokens over the number of days in the range."},"daily":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string","description":"UTC day, YYYY-MM-DD."},"totalTokens":{"type":"number"},"inputTokens":{"type":"number"},"outputTokens":{"type":"number"},"carbonKg":{"type":"number"},"electricityKwh":{"type":"number"},"waterLiters":{"type":"number"}},"required":["date","totalTokens","inputTokens","outputTokens","carbonKg","electricityKwh","waterLiters"]}},"byProvider":{"type":"array","items":{"type":"object","properties":{"provider":{"type":"string"},"totalTokens":{"type":"number"},"pct":{"type":"number","description":"Share of the range totalTokens, one decimal, 0–100."}},"required":["provider","totalTokens","pct"]}},"methodology":{"type":"object","properties":{"factorsVersion":{"type":"string","example":"v1.2"},"framework":{"type":"string"}},"required":["factorsVersion","framework"]},"computedAt":{"type":"string","description":"ISO-8601; when the backend computed this payload."}},"required":["range","totals","avgDailyTokens","daily","byProvider","methodology","computedAt"]},"PublicOpenRouterUsage":{"type":"object","properties":{"asOf":{"type":"string","description":"YYYY-MM-DD of the last successful dataset sync."},"coverageEnd":{"type":"string","description":"YYYY-MM-DD; the last day the dataset covered at the last sync. Months whose last day is after this are served as partial."},"months":{"type":"array","items":{"type":"object","properties":{"month":{"type":"string","description":"Calendar month, YYYY-MM (UTC)."},"tokens":{"type":"number"},"partial":{"type":"boolean","description":"Present and true only for a month the dataset had not fully covered."}},"required":["month","tokens"]}},"byMonth":{"type":"array","items":{"type":"object","properties":{"month":{"type":"string"},"total":{"type":"number"},"providers":{"type":"array","items":{"type":"object","properties":{"slug":{"type":"string"},"name":{"type":"string"},"tokens":{"type":"number"},"pct":{"type":"number"}},"required":["slug","name","tokens","pct"]}},"models":{"type":"array","items":{"type":"object","properties":{"slug":{"type":"string","description":"OpenRouter permaslug, e.g. deepseek/deepseek-v4-flash-20260731."},"name":{"type":"string"},"provider":{"type":"string"},"providerSlug":{"type":"string"},"version":{"type":"string","description":"ISO date of the model version, when the permaslug carries one."},"free":{"type":"boolean"},"tokens":{"type":"number"},"pct":{"type":"number"}},"required":["slug","name","provider","providerSlug","free","tokens","pct"]}}},"required":["month","total","providers","models"]}},"sourceUrl":{"type":"string"},"computedAt":{"type":"string","description":"ISO-8601; when the backend computed this payload."},"windows":{"type":"object","properties":{"30d":{"$ref":"#/components/schemas/PublicShowcaseUsage"},"365d":{"$ref":"#/components/schemas/PublicShowcaseUsage"}},"description":"The 30 and 365 day figures of the dashboard demo's OpenRouter connection, the same numbers that connection's page on /openrouter-demo shows, each in the GET /api/v1/public/usage/crbonlabs shape. They count that one connection only, never the demo's sample connections, so `byProvider` is its single `openrouter` row, not a split by model vendor. OpenRouter's public dataset publishes no request counts, so `totals.requestCount` is not a count of OpenRouter requests. A window that cannot be computed is left out, never zero-filled; with none left, so is `windows`."}},"required":["asOf","coverageEnd","months","byMonth","sourceUrl","computedAt"]},"PartnerWhoami":{"type":"object","properties":{"partner":{"type":"string","description":"The name of your partner account.","example":"Acme Gateway"},"environment":{"type":"string","enum":["test","live"],"description":"The environment of this key. A test key reads and writes test data only, and a live key live data only.","example":"test"},"scopes":{"type":"array","items":{"type":"string","enum":["usage:write","usage:read"]},"description":"What this key may do. usage:write: send events. usage:read: read events and totals.","example":["usage:write","usage:read"]}},"required":["partner","environment","scopes"],"description":"Who a partner key belongs to."},"PartnerError":{"type":"object","properties":{"success":{"type":"boolean","enum":[false],"description":"Always false on an error."},"error":{"type":"string","enum":["INVALID_BODY","UNAUTHORIZED","FORBIDDEN_SCOPE","NOT_FOUND","PAYLOAD_TOO_LARGE","RATE_LIMITED","DAILY_LIMIT_REACHED","SERVICE_UNAVAILABLE"],"description":"A stable code. Match on this, not on message. Each status names the codes it can carry.","example":"UNAUTHORIZED"},"message":{"type":"string","description":"What went wrong, in a sentence for a person to read. The wording can change.","example":"A valid partner API key is required"},"details":{"type":"object","additionalProperties":{},"description":"Present on some errors. DAILY_LIMIT_REACHED: limit and resets_at, the next UTC midnight. RATE_LIMITED: limit and retry_after (seconds) for your own limits, or retryAfter (seconds) for the limit per address. INVALID_BODY: location and field for a field the schema does not name, parameter for a bad query parameter, or limit and new_events for a call with more new events than your daily limit.","example":{"limit":100000,"resets_at":"2026-11-12T00:00:00Z"}}},"required":["success","error","message"],"description":"The body of every error the partner routes answer."},"PartnerEventResult":{"type":"object","properties":{"id":{"type":"string","description":"Your request ID, as you sent it.","example":"req_01HZX"},"status":{"type":"string","enum":["created","duplicate"],"description":"created: stored by this call. duplicate: we already held this ID with the same content, so this is the result first issued, and nothing is counted twice.","example":"created"},"outcome":{"type":"string","enum":["estimated","not_covered"],"description":"estimated: the event has figures. not_covered: we have no factor (the energy, carbon and water values per token we use) for its model or modality, so every figure is null. A not-covered event is still stored and counted in totals.","example":"estimated"},"reason":{"type":"string","enum":["unknown_model","unsupported_modality"],"description":"Present only when outcome is not_covered. unknown_model: no factor matches the model. unsupported_modality: the modality is not text.","example":"unknown_model"},"match":{"type":["string","null"],"enum":["exact","family",null],"description":"How the model was matched to a factor. exact: one model name. family: a pattern for a family of models, shown in matched_model. Null when outcome is not_covered.","example":"family"},"matched_model":{"type":["string","null"],"description":"The model name or family pattern whose factor was used. Null when outcome is not_covered.","example":"claude-sonnet*"},"methodology":{"type":["string","null"],"description":"The methodology version in force when the event was stored. A not-covered event carries it too.","example":"crbonfree-v1.2"},"factors_version":{"type":["string","null"],"description":"The version of the factor set in force when the event was stored. A not-covered event carries it too.","example":"v1.2"},"co2e_g":{"type":["string","null"],"description":"Grams of CO2e (carbon dioxide equivalent), a decimal string with six places. co2e_g_low and co2e_g_high give the range around it. Null when outcome is not_covered.","example":"0.219063"},"co2e_g_low":{"type":["string","null"],"description":"Low end of the CO2e range, grams. Null when outcome is not_covered.","example":"0.157102"},"co2e_g_high":{"type":["string","null"],"description":"High end of the CO2e range, grams. Null when outcome is not_covered.","example":"0.281023"},"energy_wh":{"type":["string","null"],"description":"Energy in watt-hours. Null when outcome is not_covered.","example":"0.088611"},"water_ml":{"type":["string","null"],"description":"Water in millilitres. Null when outcome is not_covered.","example":"1.539140"},"water_ml_low":{"type":["string","null"],"description":"Low end of the water range, millilitres. Null when outcome is not_covered.","example":"0.769570"},"water_ml_high":{"type":["string","null"],"description":"High end of the water range, millilitres. Null when outcome is not_covered.","example":"2.308709"}},"required":["id","status","outcome","match","matched_model","methodology","factors_version","co2e_g","co2e_g_low","co2e_g_high","energy_wh","water_ml","water_ml_low","water_ml_high"],"description":"The result of a stored event: created now, or a duplicate of one we already held."},"PartnerConflictResult":{"type":"object","properties":{"id":{"type":"string","description":"Your request ID, as you sent it.","example":"req_01HZX"},"status":{"type":"string","enum":["conflict"],"description":"We already hold this ID with different content. Nothing changed. Send new content under a new ID."}},"required":["id","status"],"description":"An ID that is already stored with different content."},"PartnerInvalidResult":{"type":"object","properties":{"id":{"type":["string","null"],"description":"Your request ID, as you sent it, or null when the id you sent was not a string.","example":"req_01HZX"},"status":{"type":"string","enum":["invalid"],"description":"This event was not stored. The other events in the call were still processed."},"reason":{"type":"string","description":"Why. invalid_field:<name>: that field has a value the schema refuses (the first such field). no_usage: a text event whose token counts are all 0. occurred_at_out_of_range: a new event more than 5 minutes ahead or more than 90 days old. id_repeated_in_call: an earlier event in the same call had this ID and different content, and was not stored because of its occurred_at or its customer. customer_deleting: this customer is being deleted; send the event again later. Fix the event for any other reason.","example":"invalid_field:occurred_at"}},"required":["id","status","reason"],"description":"An event that was not stored."},"PartnerUsageEventsResponse":{"type":"object","properties":{"results":{"type":"array","items":{"anyOf":[{"$ref":"#/components/schemas/PartnerEventResult"},{"$ref":"#/components/schemas/PartnerConflictResult"},{"$ref":"#/components/schemas/PartnerInvalidResult"}]},"description":"One result per event, in the order you sent them."}},"required":["results"]},"PartnerStoredEvent":{"type":"object","properties":{"id":{"type":"string","description":"Your request ID, as you sent it.","example":"req_01HZX"},"outcome":{"type":"string","enum":["estimated","not_covered"],"description":"estimated: the event has figures. not_covered: we have no factor (the energy, carbon and water values per token we use) for its model or modality, so every figure is null. A not-covered event is still stored and counted in totals.","example":"estimated"},"reason":{"type":"string","enum":["unknown_model","unsupported_modality"],"description":"Present only when outcome is not_covered. unknown_model: no factor matches the model. unsupported_modality: the modality is not text.","example":"unknown_model"},"match":{"type":["string","null"],"enum":["exact","family",null],"description":"How the model was matched to a factor. exact: one model name. family: a pattern for a family of models, shown in matched_model. Null when outcome is not_covered.","example":"family"},"matched_model":{"type":["string","null"],"description":"The model name or family pattern whose factor was used. Null when outcome is not_covered.","example":"claude-sonnet*"},"methodology":{"type":["string","null"],"description":"The methodology version in force when the event was stored. A not-covered event carries it too.","example":"crbonfree-v1.2"},"factors_version":{"type":["string","null"],"description":"The version of the factor set in force when the event was stored. A not-covered event carries it too.","example":"v1.2"},"co2e_g":{"type":["string","null"],"description":"Grams of CO2e (carbon dioxide equivalent), a decimal string with six places. co2e_g_low and co2e_g_high give the range around it. Null when outcome is not_covered.","example":"0.219063"},"co2e_g_low":{"type":["string","null"],"description":"Low end of the CO2e range, grams. Null when outcome is not_covered.","example":"0.157102"},"co2e_g_high":{"type":["string","null"],"description":"High end of the CO2e range, grams. Null when outcome is not_covered.","example":"0.281023"},"energy_wh":{"type":["string","null"],"description":"Energy in watt-hours. Null when outcome is not_covered.","example":"0.088611"},"water_ml":{"type":["string","null"],"description":"Water in millilitres. Null when outcome is not_covered.","example":"1.539140"},"water_ml_low":{"type":["string","null"],"description":"Low end of the water range, millilitres. Null when outcome is not_covered.","example":"0.769570"},"water_ml_high":{"type":["string","null"],"description":"High end of the water range, millilitres. Null when outcome is not_covered.","example":"2.308709"}},"required":["id","outcome","match","matched_model","methodology","factors_version","co2e_g","co2e_g_low","co2e_g_high","energy_wh","water_ml","water_ml_low","water_ml_high"],"description":"The stored result of one event, exactly as POST /usage/events first issued it, without status."},"PartnerFootprintCoverage":{"type":"object","properties":{"exact":{"type":"integer","description":"Estimated events whose model matched one model name.","example":0},"family":{"type":"integer","description":"Estimated events whose model matched a family pattern.","example":1},"not_covered":{"type":"integer","description":"Events with no figures. They count in requests and are left out of the figures.","example":0}},"required":["exact","family","not_covered"],"description":"How the events were matched. The three counts add up to requests."},"PartnerFootprintGroup":{"type":"object","properties":{"date":{"type":"string","description":"A UTC day, YYYY-MM-DD.","example":"2026-11-11"},"requests":{"type":"integer","description":"Every event that day, covered or not.","example":1},"co2e_g":{"type":["string","null"],"description":"Grams of CO2e, a decimal string with six places: the exact sum of the stored figures. Null when no event that day is estimated.","example":"0.219063"},"co2e_g_low":{"type":["string","null"],"description":"Low end of the CO2e range, grams. Null when no event that day is estimated.","example":"0.157102"},"co2e_g_high":{"type":["string","null"],"description":"High end of the CO2e range, grams. Null when no event that day is estimated.","example":"0.281023"},"energy_wh":{"type":["string","null"],"description":"Energy in watt-hours. Null when no event that day is estimated.","example":"0.088611"},"water_ml":{"type":["string","null"],"description":"Water in millilitres. Null when no event that day is estimated.","example":"1.539140"},"water_ml_low":{"type":["string","null"],"description":"Low end of the water range, millilitres. Null when no event that day is estimated.","example":"0.769570"},"water_ml_high":{"type":["string","null"],"description":"High end of the water range, millilitres. Null when no event that day is estimated.","example":"2.308709"},"coverage":{"$ref":"#/components/schemas/PartnerFootprintCoverage"}},"required":["date","requests","co2e_g","co2e_g_low","co2e_g_high","energy_wh","water_ml","water_ml_low","water_ml_high","coverage"],"description":"The totals of one UTC day."},"PartnerFootprint":{"type":"object","properties":{"from":{"type":"string","description":"The start of the range, inclusive, in UTC.","example":"2026-01-01T00:00:00Z"},"to":{"type":"string","description":"The end of the range, exclusive, in UTC.","example":"2027-01-01T00:00:00Z"},"methodologies":{"type":"array","items":{"type":"string"},"description":"The methodology versions of the events in the range, sorted. Empty when the range has no events.","example":["crbonfree-v1.2"]},"totals":{"type":"object","properties":{"requests":{"type":"integer","description":"Every event in the range, covered or not.","example":1},"co2e_g":{"type":["string","null"],"description":"Grams of CO2e, a decimal string with six places: the exact sum of the stored figures. Null when no event in the range is estimated.","example":"0.219063"},"co2e_g_low":{"type":["string","null"],"description":"Low end of the CO2e range, grams. Null when no event in the range is estimated.","example":"0.157102"},"co2e_g_high":{"type":["string","null"],"description":"High end of the CO2e range, grams. Null when no event in the range is estimated.","example":"0.281023"},"energy_wh":{"type":["string","null"],"description":"Energy in watt-hours. Null when no event in the range is estimated.","example":"0.088611"},"water_ml":{"type":["string","null"],"description":"Water in millilitres. Null when no event in the range is estimated.","example":"1.539140"},"water_ml_low":{"type":["string","null"],"description":"Low end of the water range, millilitres. Null when no event in the range is estimated.","example":"0.769570"},"water_ml_high":{"type":["string","null"],"description":"High end of the water range, millilitres. Null when no event in the range is estimated.","example":"2.308709"}},"required":["requests","co2e_g","co2e_g_low","co2e_g_high","energy_wh","water_ml","water_ml_low","water_ml_high"],"description":"The sums over every event in the range."},"coverage":{"$ref":"#/components/schemas/PartnerFootprintCoverage"},"groups":{"type":"array","items":{"$ref":"#/components/schemas/PartnerFootprintGroup"},"description":"Empty unless group_by=day. Then one entry for each UTC day that has events, oldest first.","example":[]}},"required":["from","to","methodologies","totals","coverage","groups"],"description":"Totals for the events of one customer, or of all your customers, with from <= occurred_at < to. A customer being deleted is left out."}}},"paths":{"/api/v1/projects":{"get":{"operationId":"projects.list","tags":["Projects"],"summary":"List projects","description":"Lists projects in the active organization. With `?include=usage`, returns per-project connection count + last-30d CO₂ rollup.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","enum":["usage"]},"required":false,"name":"include","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":500,"default":100},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Projects list","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"projects":{"anyOf":[{"type":"array","items":{"$ref":"#/components/schemas/ProjectPublic"}},{"type":"array","items":{"$ref":"#/components/schemas/ProjectWithUsage"}}]}},"required":["projects"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/usage/summary":{"get":{"operationId":"usage.getSummary","tags":["Usage"],"summary":"Get usage summary","description":"Returns totals (tokens/cost/carbon/energy/offset) plus a daily chart for the requested date range, optionally scoped to a project. Supply `startDate` + `endDate` (YYYY-MM-DD, together, max 366 days) for a custom period; they take precedence over `range`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","enum":["7d","30d","90d","365d"],"default":"30d"},"required":false,"name":"range","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"startDate","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"endDate","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"projectId","in":"query"}],"responses":{"200":{"description":"Usage summary","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/UsageSummary"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/usage/breakdown":{"get":{"operationId":"usage.getBreakdown","tags":["Usage"],"summary":"Get per-model breakdown","description":"Returns per-model token/cost/carbon/energy rollups (with `percentage` share of total tokens) for the requested date range, optionally scoped to a project. Supply `startDate` + `endDate` (YYYY-MM-DD, together, max 366 days) for a custom period; they take precedence over `range`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","enum":["7d","30d","90d","365d"],"default":"30d"},"required":false,"name":"range","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"startDate","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"endDate","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"projectId","in":"query"}],"responses":{"200":{"description":"Per-model breakdown","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"array","items":{"$ref":"#/components/schemas/UsageBreakdownItem"}}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/usage/daily":{"get":{"operationId":"usage.getDaily","tags":["Usage"],"summary":"Get daily aggregates","description":"Returns flat daily token/cost/carbon rows for the requested date range, optionally scoped to a project. Supply `startDate` + `endDate` (YYYY-MM-DD, together, max 366 days) for a custom period; they take precedence over `range`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","enum":["7d","30d","90d","365d"],"default":"30d"},"required":false,"name":"range","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"startDate","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"endDate","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"projectId","in":"query"}],"responses":{"200":{"description":"Daily aggregates","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"array","items":{"$ref":"#/components/schemas/DailyUsageRow"}}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/usage/export":{"get":{"operationId":"usage.exportDaily","tags":["Usage"],"summary":"Export daily aggregates as CSV or JSON","description":"Returns a downloadable file (CSV uses RFC-4180 quoting; JSON is a flat array — no envelope). The `format` query selects the content type. When `projectId` is set, every row carries that project's name in the `project_name` column. Supply `startDate` + `endDate` (YYYY-MM-DD, together, max 366 days) for a custom period; the filename then reflects those bounds instead of the preset.\n\n`connectionId` and `connectionType` (api | oauth | agent | browser) narrow either mode to those connections; a connection from another organization matches nothing.\n\n`detail=full` returns one row per UTC day × model × connection × project × person (`UsageExportFullRow`), sorted by date, connection, model, project and person, in a file named `crbon-usage-full-<range>-<today>.<format>`. With a signed-in (Clerk) session, an admin's export covers every person and anyone else's covers only their own usage. API-key callers get no person data: `person_key` and `person_name` are empty (null in JSON) and the rows are not split by person; the totals are the same. `provider_cost_usd` is empty (CSV) or null (JSON) where no event reported a provider cost. In the full CSV, a text cell that starts with =, +, -, @, a tab or a carriage return is prefixed with a single quote so a spreadsheet won't run it as a formula; JSON is not changed. Above 200,000 rows it answers 413 `EXPORT_TOO_LARGE`: narrow the date range or filter. The default, `detail=daily`, is the daily file as always.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","enum":["7d","30d","90d","365d"],"default":"30d"},"required":false,"name":"range","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"startDate","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"endDate","in":"query"},{"schema":{"type":"string","enum":["csv","json"],"default":"csv"},"required":false,"name":"format","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"projectId","in":"query"},{"schema":{"type":"string","enum":["daily","full"],"default":"daily"},"required":false,"name":"detail","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"connectionId","in":"query"},{"schema":{"type":"string","enum":["api","oauth","agent","browser"]},"required":false,"name":"connectionType","in":"query"}],"responses":{"200":{"description":"Exported file (CSV or JSON depending on `format` param); `detail=full` rows are `UsageExportFullRow`","content":{"text/csv":{"schema":{"type":"string"}},"application/json":{"schema":{"anyOf":[{"type":"array","items":{"$ref":"#/components/schemas/DailyUsageExportRow"}},{"type":"array","items":{"$ref":"#/components/schemas/UsageExportFullRow"}}]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Too large — a `detail=full` export over 200,000 rows (EXPORT_TOO_LARGE); narrow the date range or filter","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/telemetry/summary":{"get":{"operationId":"telemetry.getSummary","tags":["Telemetry"],"summary":"Get telemetry summary","description":"Returns CO2 totals (with upper/lower bounds), cached-vs-uncached token split, per-model rollups, and a daily chart for the requested date range, optionally scoped to a project.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"start_date","in":"query"},{"schema":{"type":"string","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"required":false,"name":"end_date","in":"query"},{"schema":{"type":"string","format":"uuid"},"required":false,"name":"project_id","in":"query"}],"responses":{"200":{"description":"Telemetry summary","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/TelemetrySummary"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/telemetry/models":{"get":{"operationId":"telemetry.listModels","tags":["Telemetry"],"summary":"List distinct telemetry models","description":"Returns the set of distinct provider/model pairs seen in the org with total tokens, total CO2, event count, and first/last-seen timestamps.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"maximum":500,"default":100},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Distinct models","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"models":{"type":"array","items":{"$ref":"#/components/schemas/TelemetryModel"}}},"required":["models"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/retirement-status":{"get":{"operationId":"billing.getRetirementStatus","tags":["Billing"],"summary":"Get carbon retirement status","description":"Customer-facing snapshot of the current billing period's carbon-retirement lifecycle: a translated status (collecting → calculating → awaiting_payment → retiring → retired / pending_signature / action_required), the period's carbon + electricity totals, the amount charged, and a receipt summary (null until credits are retired). Scoped to the authenticated organization. 404 when the org has no periods yet.","security":[{"bearerAuth":[]},{"apiKey":[]}],"responses":{"200":{"description":"Current retirement status","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"retirementStatus":{"$ref":"#/components/schemas/RetirementStatus"}},"required":["retirementStatus"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/receipts":{"get":{"operationId":"billing.listReceipts","tags":["Billing"],"summary":"List billing periods with their carbon receipt and statement","description":"Paginated, billing-period-driven list: one entry per closed period that has a carbon receipt or a footprint statement, including a usage-based billing month's, shown on that month's period. `receipt` is null when the period retired no carbon; `statementId` links its footprint statement. Paywalled: free-tier orgs receive 402 PAYMENT_REQUIRED with an `upgradeUrl`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"default":1},"required":false,"name":"page","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":100,"default":20},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Paginated billing-period receipt entries","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"array","items":{"$ref":"#/components/schemas/ReceiptListEntry"}},"pagination":{"$ref":"#/components/schemas/PaginationMeta"}},"required":["success","data","pagination"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/receipts/{id}":{"get":{"operationId":"billing.getReceipt","tags":["Billing"],"summary":"Get a carbon receipt","description":"Returns a single receipt by id, scoped to the caller's organization. Paywalled.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000001"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Carbon receipt","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"receipt":{"$ref":"#/components/schemas/CarbonReceipt"}},"required":["receipt"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/statements":{"get":{"operationId":"billing.listStatements","tags":["Billing"],"summary":"List footprint statements","description":"Paginated list of the org's prepared or Trust-signed footprint statements, newest first. Paywalled: free-tier orgs receive 402 PAYMENT_REQUIRED with an `upgradeUrl`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"default":1},"required":false,"name":"page","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":100,"default":20},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Paginated footprint statements","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"array","items":{"$ref":"#/components/schemas/TrustSignedStatement"}},"pagination":{"$ref":"#/components/schemas/PaginationMeta"}},"required":["success","data","pagination"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/statements/{id}":{"get":{"operationId":"billing.getStatement","tags":["Billing"],"summary":"Get a footprint statement","description":"Returns the prepared or Trust-signed footprint statement for the statementId returned by the receipt list. It is scoped to the authenticated organization and includes close-time usage, footprint totals, and Trust links when signed. Paywalled.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000001"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Footprint statement","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"statement":{"$ref":"#/components/schemas/TrustSignedStatement"}},"required":["statement"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/audit-packs":{"get":{"operationId":"billing.listAuditPacks","tags":["Billing"],"summary":"List audit packs","description":"Paginated list of generated audit packs (one per month, ZIP exports of receipts + manifest). Paywalled.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"integer","minimum":1,"default":1},"required":false,"name":"page","in":"query"},{"schema":{"type":"integer","minimum":1,"maximum":100,"default":20},"required":false,"name":"limit","in":"query"}],"responses":{"200":{"description":"Paginated audit packs","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"array","items":{"$ref":"#/components/schemas/AuditPack"}},"pagination":{"$ref":"#/components/schemas/PaginationMeta"}},"required":["success","data","pagination"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/billing/audit-packs/{id}":{"get":{"operationId":"billing.getAuditPack","tags":["Billing"],"summary":"Get an audit pack","description":"Returns a single audit pack by id, scoped to the caller's organization. Paywalled.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","format":"uuid","example":"00000000-0000-0000-0000-000000000001"},"required":true,"name":"id","in":"path"}],"responses":{"200":{"description":"Audit pack","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"type":"object","properties":{"auditPack":{"$ref":"#/components/schemas/AuditPack"}},"required":["auditPack"]}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment required — feature gated behind paid tier; clients should redirect to upgradeUrl","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/carbon-factors":{"get":{"operationId":"carbonFactors.list","tags":["Factors"],"summary":"List carbon factor versions","description":"Returns every emissions factor version, oldest first, with whether it is the active writer version and whether it carries the v1.2 layered-emissions factors.","security":[{"bearerAuth":[]},{"apiKey":[]}],"responses":{"200":{"description":"Factor versions","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/CarbonFactorVersionList"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Factor configuration is inconsistent or the active version is not seeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/carbon-factors/current":{"get":{"operationId":"carbonFactors.getCurrent","tags":["Factors"],"summary":"Get the active carbon factor set","description":"Returns the factor set the pipeline currently writes new calculations with. Responds 503 if that version is not seeded, rather than falling back to another version.","security":[{"bearerAuth":[]},{"apiKey":[]}],"responses":{"200":{"description":"Active factor set","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/CarbonFactorSet"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Factor configuration is inconsistent or the active version is not seeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/carbon-factors/{version}":{"get":{"operationId":"carbonFactors.getByVersion","tags":["Factors"],"summary":"Get one carbon factor version","description":"Returns the full factor set for a specific version, e.g. `v1.1`.","security":[{"bearerAuth":[]},{"apiKey":[]}],"parameters":[{"schema":{"type":"string","maxLength":20,"pattern":"^v\\d+\\.\\d+$","example":"v1.2"},"required":true,"name":"version","in":"path"}],"responses":{"200":{"description":"Factor set for the version","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/CarbonFactorSet"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Factor configuration is inconsistent or the active version is not seeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/public/total-tokens":{"get":{"operationId":"publicStats.getTotalTokens","tags":["Usage"],"summary":"Get cumulative tokens tracked","description":"Returns the platform-wide cumulative token total across every organization, all time. No auth required — powers the public landing page counter. Cached for 60 seconds.","security":[],"responses":{"200":{"description":"Cumulative token total","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/PublicTotalTokens"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/public/emissions-estimate":{"post":{"operationId":"publicStats.estimateEmissions","tags":["Usage"],"summary":"Estimate CO2e, electricity, and water from token buckets","description":"Runs the exact same factor-resolution and emissions math path the worker uses before writing carbon_calculations. Accepts a model id plus token buckets and returns CO2e, electricity, and water estimates with the same metadata fields the worker persists.","security":[],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PublicEmissionsEstimateRequest"}}}},"responses":{"200":{"description":"Emissions estimate","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/PublicEmissionsEstimate"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/public/usage/crbonlabs":{"get":{"operationId":"publicUsage.getCrbonLabs","tags":["Usage"],"summary":"Crbon Labs' own AI usage footprint","description":"Aggregate AI usage and emissions for Crbon Labs Inc.'s own organisation over a trailing window — the same numbers the product dashboard shows, to the token. Aggregates only: no events, users, keys, connections or cost. No auth required — powers the public landing and case study. Cached for 30 minutes; `computedAt` is when the payload was computed.","security":[],"parameters":[{"schema":{"type":"string","enum":["7d","30d","90d","365d"],"default":"365d","description":"Trailing window in UTC days — the same presets GET /api/v1/usage/summary accepts.","example":"365d"},"required":false,"name":"range","in":"query"}],"responses":{"200":{"description":"Showcase usage","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/PublicShowcaseUsage"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Not available — showcase organisation not configured, or the OpenRouter dataset has not been synced yet","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/public/usage/openrouter":{"get":{"operationId":"publicUsage.getOpenRouter","tags":["Usage"],"summary":"OpenRouter public usage series","description":"Monthly token totals from OpenRouter's public rankings dataset (https://openrouter.ai/rankings), with the provider share stack and top models for every complete month. Synced daily by the backend. No auth required. Cached for 30 minutes; `asOf` is the last successful sync, `computedAt` when the payload was computed. The optional `windows` carries the 30 and 365 day figures of the dashboard demo's OpenRouter connection (the numbers its page on /openrouter-demo shows) and is left out when they cannot be computed.","security":[],"responses":{"200":{"description":"OpenRouter series","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean","enum":[true]},"data":{"$ref":"#/components/schemas/PublicOpenRouterUsage"}},"required":["success","data"]}}}},"400":{"description":"Bad request — validation failed or malformed JSON body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized — token missing, expired, or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Too many requests — rate limit exceeded","headers":{"Retry-After":{"schema":{"type":"integer"},"description":"Seconds until next request allowed"},"X-RateLimit-Limit":{"schema":{"type":"integer"}},"X-RateLimit-Remaining":{"schema":{"type":"integer"}},"X-RateLimit-Reset":{"schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"Not available — showcase organisation not configured, or the OpenRouter dataset has not been synced yet","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/v1/partner/whoami":{"get":{"tags":["Partner"],"operationId":"partner.whoami","security":[{"partnerKey":[]}],"summary":"Check a partner key","description":"Returns the partner, environment and scopes of the key you send. Any valid partner key may call it, so it is the quickest check that a key works.","responses":{"200":{"description":"The key is valid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerWhoami"}}}},"401":{"description":"UNAUTHORIZED: the key is missing, malformed, unknown or revoked, or the account is disabled. Every one of these gets the same answer.","headers":{"WWW-Authenticate":{"description":"Always Bearer realm=\"crbonfree-partner\".","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"429":{"description":"RATE_LIMITED: more than 1,200 calls a minute from your address.","headers":{"Retry-After":{"description":"Seconds to wait before you call again.","schema":{"type":"integer","minimum":1}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"503":{"description":"SERVICE_UNAVAILABLE: our failure. Try again.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}}}}},"/api/v1/partner/usage/events":{"post":{"tags":["Partner"],"operationId":"partner.usage.ingest","security":[{"partnerKey":[]}],"summary":"Send usage events","description":"Stores up to 1,000 usage events for your customers and returns the footprint of each, in the order sent. If a call fails or times out, send the same events again with the same IDs: anything already stored comes back as duplicate and is not counted twice. A field the schema does not name, anywhere in the body, refuses the whole call. Each call counts against your limits for calls and events a minute, and for new events a UTC day.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerUsageEventsRequest"}}}},"responses":{"200":{"description":"One result per event: created, duplicate, conflict or invalid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerUsageEventsResponse"}}}},"400":{"description":"INVALID_BODY: the body is not JSON, is not { \"events\": [ ... ] } with 1 to 1,000 events, has a field the schema does not name, or has more new events than your daily limit. Nothing is stored.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"401":{"description":"UNAUTHORIZED: the key is missing, malformed, unknown or revoked, or the account is disabled. Every one of these gets the same answer.","headers":{"WWW-Authenticate":{"description":"Always Bearer realm=\"crbonfree-partner\".","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"403":{"description":"FORBIDDEN_SCOPE: the key does not have usage:write.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"413":{"description":"PAYLOAD_TOO_LARGE: the body is larger than 2 MB. Nothing is stored.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"429":{"description":"RATE_LIMITED: too many calls or events a minute for your account in this environment, or too many calls from your address. DAILY_LIMIT_REACHED: the new events of this call would pass your daily limit for this UTC day; details.resets_at says when it resets. Nothing is stored. Wait for Retry-After, then send the same events again.","headers":{"Retry-After":{"description":"Seconds to wait before you call again.","schema":{"type":"integer","minimum":1}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"503":{"description":"SERVICE_UNAVAILABLE: our failure. You cannot tell whether the events were stored, so send the same events again with the same IDs.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}}}}},"/api/v1/partner/usage/events/{id}":{"get":{"tags":["Partner"],"operationId":"partner.usage.event","security":[{"partnerKey":[]}],"summary":"Read one usage event","description":"Returns the stored result of one event, exactly as POST /usage/events first issued it, without status. URL-encode the ID.","parameters":[{"name":"id","in":"path","required":true,"description":"Your request ID, as you sent it in events[].id, URL-encoded.","schema":{"type":"string","minLength":1,"maxLength":128,"example":"req_01HZX"}}],"responses":{"200":{"description":"The stored result of the event.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerStoredEvent"}}}},"401":{"description":"UNAUTHORIZED: the key is missing, malformed, unknown or revoked, or the account is disabled. Every one of these gets the same answer.","headers":{"WWW-Authenticate":{"description":"Always Bearer realm=\"crbonfree-partner\".","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"403":{"description":"FORBIDDEN_SCOPE: the key does not have usage:read.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"404":{"description":"NOT_FOUND: there is no event with this ID in the environment of this key, or its customer is being deleted.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"429":{"description":"RATE_LIMITED: too many calls a minute for your account in this environment, or too many calls from your address.","headers":{"Retry-After":{"description":"Seconds to wait before you call again.","schema":{"type":"integer","minimum":1}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"503":{"description":"SERVICE_UNAVAILABLE: our failure. Try again. A read that fails answers 503, not a zero.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}}}}},"/api/v1/partner/usage/footprint":{"get":{"tags":["Partner"],"operationId":"partner.usage.footprint","security":[{"partnerKey":[]}],"summary":"Read footprint totals","description":"Totals for the events with from <= occurred_at < to, over at most 366 days, for one customer or all of them. Not-covered events count in requests and coverage and are left out of the figures. When no event in the range is estimated, the figures are null. An unknown customer gets the same answer as a customer with no events.","parameters":[{"name":"from","in":"query","required":true,"description":"The start of the range, inclusive. An RFC 3339 date and time with a time zone, such as 2026-10-01T00:00:00Z. Write a + in the time zone as %2B.","schema":{"type":"string","format":"date-time","example":"2026-01-01T00:00:00Z"}},{"name":"to","in":"query","required":true,"description":"The end of the range, exclusive. An RFC 3339 date and time with a time zone, such as 2026-10-01T00:00:00Z. Write a + in the time zone as %2B.","schema":{"type":"string","format":"date-time","example":"2027-01-01T00:00:00Z"}},{"name":"customer_id","in":"query","required":false,"description":"Your ID for one customer, as sent in events[].customer_id. Without it, the totals cover all your customers.","schema":{"type":"string","pattern":"^[A-Za-z0-9._:@-]{1,128}$","example":"acct_8f2c"}},{"name":"group_by","in":"query","required":false,"description":"day: also return the totals of each UTC day that has events, in groups.","schema":{"type":"string","enum":["day"]}}],"responses":{"200":{"description":"The totals for the range.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerFootprint"}}}},"400":{"description":"INVALID_BODY: from or to is missing or not a date and time with a time zone, to is not after from, the range is longer than 366 days, a parameter is unknown or given twice, customer_id or group_by is not valid, or the range holds too many events to total in time. Then ask for a narrower range.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"401":{"description":"UNAUTHORIZED: the key is missing, malformed, unknown or revoked, or the account is disabled. Every one of these gets the same answer.","headers":{"WWW-Authenticate":{"description":"Always Bearer realm=\"crbonfree-partner\".","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"403":{"description":"FORBIDDEN_SCOPE: the key does not have usage:read.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"429":{"description":"RATE_LIMITED: too many calls a minute for your account in this environment, or too many calls from your address.","headers":{"Retry-After":{"description":"Seconds to wait before you call again.","schema":{"type":"integer","minimum":1}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}},"503":{"description":"SERVICE_UNAVAILABLE: our failure. Try again. A read that fails answers 503, not a zero.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerError"}}}}}}}},"webhooks":{}}