{
  "openapi": "3.1.0",
  "info": {
    "title": "Codex Laboratories API",
    "version": "0.1.0",
    "description": "Public contract for the codexlabsai.com v1 API consumed by the desktop application, plus the public health and site-search endpoints. Every response uses the platform envelope: `{ \"ok\": true, \"data\": ... }` on success or `{ \"ok\": false, \"error\": { \"code\", \"message\" } }` on failure. Money fields are integer micro-USD serialized as strings (bigint-safe)."
  },
  "servers": [
    {
      "url": "https://codexlabsai.com"
    }
  ],
  "tags": [
    {
      "name": "auth",
      "description": "Application token lifecycle"
    },
    {
      "name": "account",
      "description": "Caller context"
    },
    {
      "name": "usage",
      "description": "Metered-usage ingestion and reporting"
    },
    {
      "name": "installations",
      "description": "Registered application installations"
    },
    {
      "name": "public",
      "description": "Unauthenticated utility endpoints"
    }
  ],
  "paths": {
    "/api/v1/auth/token": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Issue or rotate application tokens",
        "description": "Two grant shapes distinguished by `grant_type`. The `password` grant registers a new installation and requires the TOTP code when the account has a second factor enrolled (parity with browser login). The `refresh_token` grant rotates the pair: the presented refresh token is revoked and a new one issued. Access tokens are JWTs with a 900s lifetime and an `inst` (installation) claim; refresh tokens are opaque, single-use, 90-day TTL.",
        "operationId": "createToken",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/PasswordGrant"
                  },
                  {
                    "$ref": "#/components/schemas/RefreshGrant"
                  }
                ],
                "discriminator": {
                  "propertyName": "grant_type"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token pair issued",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "access_token": {
                              "type": "string",
                              "description": "JWT, 900s lifetime"
                            },
                            "token_type": {
                              "type": "string",
                              "enum": [
                                "Bearer"
                              ]
                            },
                            "expires_in": {
                              "type": "integer",
                              "enum": [
                                900
                              ]
                            },
                            "refresh_token": {
                              "type": "string",
                              "description": "New rotating refresh token"
                            },
                            "installation": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                }
                              },
                              "description": "Present only on the password grant"
                            },
                            "user": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "email": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                }
                              },
                              "description": "Present only on the password grant"
                            }
                          },
                          "required": [
                            "access_token",
                            "token_type",
                            "expires_in",
                            "refresh_token"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "VALIDATION or INSTALLATION_MISMATCH"
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "BAD_CREDENTIALS, TOTP_REQUIRED, BAD_TOTP, or BAD_REFRESH"
          },
          "403": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "INSTALLATION_LIMIT or INSTALLATION_REVOKED"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Log out the calling installation",
        "description": "Revokes every refresh token of the calling installation and marks the installation REVOKED. Idempotent: returns success even when the token has no installation context.",
        "operationId": "logout",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Logged out",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "loggedOut": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "loggedOut"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "NO_TOKEN or BAD_TOKEN"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/me": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Caller account context",
        "operationId": "getMe",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "User, installation and organization membership",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "user": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string"
                                },
                                "email": {
                                  "type": "string"
                                },
                                "name": {
                                  "type": "string"
                                },
                                "emailVerified": {
                                  "type": "boolean"
                                }
                              },
                              "required": [
                                "id",
                                "email",
                                "name",
                                "emailVerified"
                              ]
                            },
                            "installation": {
                              "$ref": "#/components/schemas/InstallationSummary"
                            },
                            "organizations": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "id": {
                                    "type": "string"
                                  },
                                  "name": {
                                    "type": "string"
                                  },
                                  "slug": {
                                    "type": "string"
                                  },
                                  "role": {
                                    "type": "string"
                                  }
                                }
                              }
                            }
                          },
                          "required": [
                            "user",
                            "installation",
                            "organizations"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/entitlements": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Resolve effective entitlements",
        "description": "The authoritative entitlement answer: plan catalog values merged with admin-granted EntitlementOverride rows, current-period usage totals, and spend-limit state. Pass `organizationId` for org-scoped entitlements (caller must be a member).",
        "operationId": "getEntitlements",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "organizationId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Resolved entitlements",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Entitlements"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "403": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "NOT_ORG_MEMBER"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/usage": {
      "post": {
        "tags": [
          "usage"
        ],
        "summary": "Ingest usage record(s)",
        "description": "Accepts either a single record object or a batch envelope `{ \"records\": [...] }` (max 500). Each record is idempotent by `requestId` - resubmission returns `status: \"duplicate\"` rather than double-billing. Pricing, allowances and entitlement checks are resolved server-side; client-reported token counts are measurements, not prices. Per-installation burst limit: 600 events/minute. API-key alternative: a key carrying the `usage:write` scope may submit unattributed usage (no installation context).",
        "operationId": "submitUsage",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": [
              "usage:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/UsageRecordInput"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "records": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 500,
                        "items": {
                          "$ref": "#/components/schemas/UsageRecordInput"
                        }
                      }
                    },
                    "required": [
                      "records"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Record accepted (single) or per-record results (batch)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/IngestResult"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "results": {
                                  "type": "array",
                                  "items": {
                                    "$ref": "#/components/schemas/BatchResult"
                                  }
                                }
                              },
                              "required": [
                                "results"
                              ]
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "VALIDATION"
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "403": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "INSTALLATION_REQUIRED or INSTALLATION_REVOKED"
          },
          "422": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "UsageRejection codes: BAD_REQUEST_ID, CLOCK_SKEW, MODEL_NOT_ALLOWED, ALLOWANCE_EXHAUSTED, SPEND_LIMIT_EXCEEDED, NOT_ORG_MEMBER, INSTALLATION_MISMATCH"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/usage/summary": {
      "get": {
        "tags": [
          "usage"
        ],
        "summary": "Lightweight usage snapshot",
        "operationId": "usageSummary",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Plan, current-period usage, spend limit and billing state",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "plan": {
                              "type": "object"
                            },
                            "usage": {
                              "type": "object"
                            },
                            "spendLimit": {
                              "$ref": "#/components/schemas/SpendLimit"
                            },
                            "billingActive": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "plan",
                            "usage",
                            "spendLimit",
                            "billingActive"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/installations": {
      "get": {
        "tags": [
          "installations"
        ],
        "summary": "List the account's installations",
        "operationId": "listInstallations",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Installations, newest first",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "installations": {
                              "type": "array",
                              "items": {
                                "$ref": "#/components/schemas/Installation"
                              }
                            }
                          },
                          "required": [
                            "installations"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/installations/{id}": {
      "delete": {
        "tags": [
          "installations"
        ],
        "summary": "Revoke an installation",
        "description": "Revokes the installation and all of its tokens. Uniform 404 when the installation does not exist or belongs to another account (no existence disclosure). API keys require the `installations:write` scope.",
        "operationId": "revokeInstallation",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": [
              "installations:write"
            ]
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "revoked": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "revoked"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorEnvelope"
          },
          "404": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "NOT_FOUND (uniform - includes foreign-owned ids)"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "tags": [
          "public"
        ],
        "summary": "Service health",
        "description": "Liveness plus dependency checks (database, Stripe reachability, Resend configuration). Unauthenticated; designed for monitors.",
        "operationId": "health",
        "responses": {
          "200": {
            "description": "Health snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "healthy",
                                "degraded",
                                "unhealthy"
                              ]
                            },
                            "timestamp": {
                              "type": "string",
                              "format": "date-time"
                            },
                            "checks": {
                              "type": "object"
                            }
                          },
                          "required": [
                            "status",
                            "timestamp",
                            "checks"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/ErrorEnvelope"
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "tags": [
          "public"
        ],
        "summary": "Site search",
        "description": "Searches knowledge-base articles and public pages. Rate limited to 60/minute.",
        "operationId": "siteSearch",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked results",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/OkEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "query": {
                              "type": "string"
                            },
                            "count": {
                              "type": "integer"
                            },
                            "results": {
                              "type": "array",
                              "items": {
                                "type": "object"
                              }
                            }
                          },
                          "required": [
                            "query",
                            "count",
                            "results"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ErrorEnvelope",
            "description": "QUERY_TOO_SHORT or QUERY_TOO_LONG"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Access token from POST /api/v1/auth/token (900s lifetime, `inst` claim binds it to an installation)"
      },
      "apiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Long-lived API key (axk_live_...) minted in dashboard settings; authenticates without an installation context. Per-endpoint scopes enforced: entitlements:read -> GET /api/v1/entitlements; usage:read -> GET /api/v1/usage/summary; usage:write -> POST /api/v1/usage; installations:read -> GET /api/v1/installations; installations:write -> DELETE /api/v1/installations/{id}. Missing scope -> 403 SCOPE_MISSING."
      }
    },
    "schemas": {
      "OkEnvelope": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              true
            ]
          }
        },
        "required": [
          "ok"
        ]
      },
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "ok",
          "error"
        ]
      },
      "PasswordGrant": {
        "type": "object",
        "properties": {
          "grant_type": {
            "type": "string",
            "enum": [
              "password"
            ]
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "password": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "totp": {
            "type": "string",
            "minLength": 6,
            "maxLength": 10,
            "description": "Authenticator code or XXXX-XXXX recovery code; required once TOTP is enrolled"
          },
          "installation": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "platform": {
                "type": "string",
                "enum": [
                  "windows",
                  "macos",
                  "linux",
                  "other"
                ]
              },
              "appVersion": {
                "type": "string",
                "maxLength": 40
              },
              "fingerprint": {
                "type": "string",
                "maxLength": 200
              }
            },
            "required": [
              "name"
            ]
          }
        },
        "required": [
          "grant_type",
          "email",
          "password",
          "installation"
        ]
      },
      "RefreshGrant": {
        "type": "object",
        "properties": {
          "grant_type": {
            "type": "string",
            "enum": [
              "refresh_token"
            ]
          },
          "refresh_token": {
            "type": "string",
            "minLength": 20
          },
          "installation_id": {
            "type": "string"
          }
        },
        "required": [
          "grant_type",
          "refresh_token",
          "installation_id"
        ]
      },
      "Installation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "platform": {
            "type": "string",
            "nullable": true
          },
          "appVersion": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "ACTIVE",
              "REVOKED",
              "SUSPENDED"
            ]
          },
          "lastSeenAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "revokedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "InstallationSummary": {
        "type": "object",
        "nullable": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "platform": {
            "type": "string",
            "nullable": true
          },
          "appVersion": {
            "type": "string",
            "nullable": true
          },
          "registeredAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "description": "Null when the caller authenticated with an API key (no installation context)"
      },
      "UsageRecordInput": {
        "type": "object",
        "properties": {
          "requestId": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128,
            "pattern": "^[\\w\\-:.]{8,128}$",
            "description": "Client-supplied idempotency key"
          },
          "organizationId": {
            "type": "string",
            "maxLength": 64
          },
          "workspaceId": {
            "type": "string",
            "maxLength": 128
          },
          "provider": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "model": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "mode": {
            "type": "string",
            "enum": [
              "CLOUD",
              "LOCAL"
            ],
            "default": "CLOUD"
          },
          "status": {
            "type": "string",
            "enum": [
              "SUCCESS",
              "ERROR",
              "REJECTED",
              "CANCELED"
            ],
            "default": "SUCCESS"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "description": "Client-reported; rejected beyond \u00b17 days clock skew"
          },
          "inputTokens": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "outputTokens": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "cachedTokens": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "toolCalls": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "computeMs": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "metadata": {
            "type": "object",
            "description": "Small diagnostic JSON - never prompts or source code"
          }
        },
        "required": [
          "requestId",
          "provider",
          "model",
          "occurredAt"
        ]
      },
      "IngestResult": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "duplicate"
            ]
          },
          "recordId": {
            "type": "string"
          },
          "coveredByAllowance": {
            "type": "boolean"
          },
          "chargeMicros": {
            "type": "string",
            "description": "Integer micro-USD as string (bigint-safe)"
          }
        },
        "required": [
          "status"
        ]
      },
      "BatchResult": {
        "type": "object",
        "properties": {
          "requestId": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "accepted",
              "duplicate",
              "rejected"
            ]
          },
          "recordId": {
            "type": "string"
          },
          "coveredByAllowance": {
            "type": "boolean"
          },
          "chargeMicros": {
            "type": "string"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "requestId",
          "status"
        ]
      },
      "SpendLimit": {
        "type": "object",
        "properties": {
          "limitMicros": {
            "type": "string",
            "nullable": true
          },
          "spentMicros": {
            "type": "string"
          },
          "exhausted": {
            "type": "boolean"
          }
        }
      },
      "Entitlements": {
        "type": "object",
        "properties": {
          "plan": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "FREE",
                  "PAID",
                  "ENTERPRISE"
                ]
              }
            }
          },
          "subscription": {
            "type": "object",
            "nullable": true,
            "properties": {
              "status": {
                "type": "string"
              },
              "interval": {
                "type": "string"
              },
              "currentPeriodStart": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "currentPeriodEnd": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              },
              "cancelAtPeriodEnd": {
                "type": "boolean"
              },
              "trialEndsAt": {
                "type": "string",
                "format": "date-time",
                "nullable": true
              }
            }
          },
          "features": {
            "type": "object",
            "properties": {
              "advancedAgents": {
                "type": "boolean"
              },
              "multiFileEdits": {
                "type": "boolean"
              },
              "localModels": {
                "type": "boolean"
              },
              "cloudModels": {
                "type": "boolean"
              },
              "priorityQueue": {
                "type": "boolean"
              },
              "teamWorkspaces": {
                "type": "boolean"
              },
              "sso": {
                "type": "boolean"
              },
              "auditLogExport": {
                "type": "boolean"
              },
              "dedicatedSupport": {
                "type": "boolean"
              },
              "usageAnalytics": {
                "type": "string",
                "enum": [
                  "basic",
                  "advanced",
                  "organization"
                ]
              }
            }
          },
          "limits": {
            "type": "object",
            "properties": {
              "maxInstallations": {
                "type": "integer"
              },
              "maxOrganizations": {
                "type": "integer"
              },
              "maxOrgSeats": {
                "type": "integer"
              },
              "allowedModels": {
                "oneOf": [
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  {
                    "type": "string",
                    "enum": [
                      "*"
                    ]
                  }
                ]
              },
              "allowedProviders": {
                "oneOf": [
                  {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  {
                    "type": "string",
                    "enum": [
                      "*"
                    ]
                  }
                ]
              },
              "orgRole": {
                "type": "boolean"
              }
            },
            "description": "-1 = unlimited for numeric limits"
          },
          "allowances": {
            "type": "object",
            "properties": {
              "requestsPerMonth": {
                "type": "integer"
              },
              "inputTokensPerMonth": {
                "type": "integer"
              },
              "outputTokensPerMonth": {
                "type": "integer"
              }
            },
            "description": "-1 = unlimited"
          },
          "overageEnabled": {
            "type": "boolean"
          },
          "usage": {
            "type": "object",
            "properties": {
              "periodStart": {
                "type": "string",
                "format": "date-time"
              },
              "periodEnd": {
                "type": "string",
                "format": "date-time"
              },
              "requests": {
                "type": "integer"
              },
              "inputTokens": {
                "type": "integer"
              },
              "outputTokens": {
                "type": "integer"
              },
              "requestsRemaining": {
                "type": "integer"
              },
              "inputTokensRemaining": {
                "type": "integer"
              },
              "outputTokensRemaining": {
                "type": "integer"
              },
              "billableChargesMicros": {
                "type": "string"
              }
            }
          },
          "spendLimit": {
            "$ref": "#/components/schemas/SpendLimit"
          },
          "billingActive": {
            "type": "boolean"
          }
        }
      }
    },
    "responses": {
      "ErrorEnvelope": {
        "description": "Error envelope - `error.code` is the stable machine-readable contract",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limited - honour `Retry-After`",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    }
  }
}