{
  "openapi": "3.0.0",
  "info": {
    "title": "Oneloop API",
    "version": "1.0.0",
    "description": "API Key Management"
  },
  "security": [{ "bearerAuth": [] }],
  "servers": [
    { "url": "https://prod.oneloop.ai", "description": "Production server" }
  ],
  "components": {
    "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer" } },
    "schemas": {
      "Workspace": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "teamId": { "type": "string" },
          "defaultKeyPrefix": { "type": "string", "nullable": true },
          "defaultAllowedIPs": {
            "type": "array",
            "items": { "type": "string" }
          },
          "defaultRateLimitPerSecond": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "defaultExpiration": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "createdAt": { "type": "string" },
          "updatedAt": { "type": "string" }
        },
        "required": [
          "id",
          "name",
          "teamId",
          "defaultKeyPrefix",
          "defaultAllowedIPs",
          "defaultRateLimitPerSecond",
          "defaultExpiration",
          "createdAt",
          "updatedAt"
        ]
      },
      "CreateWorkspaceResponse": {
        "type": "object",
        "properties": {
          "workspace": { "$ref": "#/components/schemas/Workspace" }
        },
        "required": ["workspace"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "number",
                "minimum": 0,
                "exclusiveMinimum": true
              },
              "message": { "type": "string" }
            },
            "required": ["code", "message"]
          }
        },
        "required": ["error"]
      },
      "CreateWorkspaceRequest": {
        "type": "object",
        "properties": { "name": { "type": "string" } },
        "required": ["name"]
      },
      "RetrieveWorkspaceResponse": {
        "type": "object",
        "properties": {
          "workspaces": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Workspace" }
          }
        },
        "required": ["workspaces"]
      },
      "RetrieveWorkspaceByIdResponse": {
        "type": "object",
        "properties": {
          "workspace": { "$ref": "#/components/schemas/Workspace" }
        },
        "required": ["workspace"]
      },
      "UpdateWorkspaceResponse": {
        "type": "object",
        "properties": {
          "workspace": { "$ref": "#/components/schemas/Workspace" }
        },
        "required": ["workspace"]
      },
      "UpdateWorkspaceRequest": {
        "type": "object",
        "properties": {
          "defaultKeyPrefix": { "type": "string", "nullable": true },
          "defaultAllowedIPs": {
            "type": "array",
            "items": { "type": "string" }
          },
          "defaultRateLimitPerSecond": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "defaultExpiration": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          }
        },
        "required": [
          "defaultKeyPrefix",
          "defaultAllowedIPs",
          "defaultRateLimitPerSecond",
          "defaultExpiration"
        ]
      },
      "WorkspaceScope": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "representation": { "type": "string" },
          "description": { "type": "string", "nullable": true },
          "createdAt": { "type": "string" },
          "updatedAt": { "type": "string" }
        },
        "required": [
          "id",
          "name",
          "representation",
          "description",
          "createdAt",
          "updatedAt"
        ]
      },
      "RetrieveAllWorkspaceScopesResponse": {
        "type": "object",
        "properties": {
          "scopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/WorkspaceScope" }
          }
        },
        "required": ["scopes"]
      },
      "CreateWorkspaceScopeResponse": {
        "type": "object",
        "properties": {
          "scope": { "$ref": "#/components/schemas/WorkspaceScope" }
        },
        "required": ["scope"]
      },
      "CreateWorkspaceScopeRequest": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "representation": { "type": "string" },
          "description": { "type": "string" }
        },
        "required": ["name", "representation"]
      },
      "ApiKeyScope": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "representation": { "type": "string" },
          "create": { "type": "boolean" },
          "read": { "type": "boolean" },
          "update": { "type": "boolean" },
          "del": { "type": "boolean" }
        },
        "required": ["representation", "create", "read", "update", "del"]
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "maskedKey": { "type": "string" },
          "prefix": { "type": "string", "nullable": true },
          "expiresAt": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "scopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKeyScope" }
          },
          "enabled": { "type": "boolean" },
          "customerId": { "type": "string", "nullable": true },
          "deleted": { "type": "boolean" },
          "createdAt": { "type": "string" },
          "updatedAt": { "type": "string" },
          "lastUsedAt": { "type": "string", "nullable": true },
          "billingId": { "type": "string", "nullable": true }
        },
        "required": [
          "id",
          "name",
          "maskedKey",
          "prefix",
          "expiresAt",
          "scopes",
          "enabled",
          "customerId",
          "deleted",
          "createdAt",
          "updatedAt",
          "lastUsedAt",
          "billingId"
        ]
      },
      "CreateApiKeyResponse": {
        "type": "object",
        "properties": {
          "apiKey": {
            "allOf": [
              { "$ref": "#/components/schemas/ApiKey" },
              {
                "type": "object",
                "properties": { "key": { "type": "string" } },
                "required": ["key"]
              }
            ]
          }
        },
        "required": ["apiKey"]
      },
      "CreateApiKeyRequest": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "workspaceId": { "type": "string" },
          "prefix": { "type": "string" },
          "expiresAt": {
            "type": "integer",
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "representation": { "type": "string" },
                "create": { "type": "boolean" },
                "read": { "type": "boolean" },
                "update": { "type": "boolean" },
                "del": { "type": "boolean" }
              },
              "required": ["representation", "create", "read", "update", "del"]
            }
          },
          "enabled": { "type": "boolean" },
          "customerId": { "type": "string" },
          "externalMeterId": { "type": "string" },
          "metadata": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          }
        },
        "required": ["name", "workspaceId", "scopes", "enabled", "customerId"]
      },
      "RetrieveApiKeysResponse": {
        "type": "object",
        "properties": {
          "apiKeys": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKey" }
          }
        },
        "required": ["apiKeys"]
      },
      "RetrieveApiKeyByIdResponse": {
        "type": "object",
        "properties": { "apiKey": { "$ref": "#/components/schemas/ApiKey" } },
        "required": ["apiKey"]
      },
      "CustomerBillingMeter": {
        "type": "object",
        "nullable": true,
        "properties": {
          "id": { "type": "string" },
          "totalCredits": { "type": "string", "pattern": "^d+$" },
          "usedCredits": { "type": "string", "pattern": "^d+$" },
          "allowOverages": { "type": "boolean" },
          "spendCap": { "type": "string", "nullable": true, "pattern": "^d+$" },
          "createdAt": { "type": "string" },
          "updatedAt": { "type": "string" }
        },
        "required": [
          "id",
          "totalCredits",
          "usedCredits",
          "allowOverages",
          "spendCap",
          "createdAt",
          "updatedAt"
        ]
      },
      "VerifyApiKeyResponse": {
        "type": "object",
        "properties": {
          "apiKeyId": { "type": "string" },
          "expiresAt": {
            "type": "integer",
            "nullable": true,
            "minimum": 0,
            "exclusiveMinimum": true
          },
          "requestedScopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKeyScope" }
          },
          "status": {
            "type": "string",
            "enum": [
              "VALID",
              "EXPIRED",
              "DISABLED",
              "DELETED",
              "RATE_LIMITED",
              "USAGE_LIMITED",
              "INVALID_SCOPES",
              "INVALID"
            ]
          },
          "rateLimit": {
            "type": "object",
            "properties": {
              "remaining": { "type": "integer" },
              "resetAt": { "type": "integer" }
            },
            "required": ["remaining", "resetAt"]
          },
          "metadata": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          },
          "billing": { "$ref": "#/components/schemas/CustomerBillingMeter" },
          "externalMeterId": { "type": "string", "nullable": true },
          "customerId": { "type": "string", "nullable": true },
          "scopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKeyScope" }
          }
        },
        "required": [
          "apiKeyId",
          "expiresAt",
          "requestedScopes",
          "status",
          "billing",
          "externalMeterId",
          "customerId",
          "scopes"
        ]
      },
      "VerifyApiKeyRequest": {
        "type": "object",
        "properties": {
          "key": { "type": "string" },
          "requestedScopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKeyScope" }
          },
          "route": { "type": "string" },
          "billing": {
            "type": "object",
            "properties": {
              "usage": {
                "type": "string",
                "pattern": "^\\d+$",
                "default": "0"
              },
              "usageName": { "type": "string" }
            }
          },
          "rateLimitConfig": {
            "type": "object",
            "properties": {
              "id": { "type": "string" },
              "limit": {
                "type": "integer",
                "minimum": 0,
                "exclusiveMinimum": true
              }
            },
            "required": ["id", "limit"]
          }
        },
        "required": ["key", "requestedScopes"]
      },
      "RecordUsageApiKeyResponse": { "type": "object", "properties": {} },
      "RecordUsageApiKeyRequest": {
        "type": "object",
        "properties": {
          "key": { "type": "string" },
          "usage": { "type": "string", "pattern": "^\\d+$", "default": "0" },
          "usageName": { "type": "string" }
        },
        "required": ["key"]
      },
      "RotateApiKeyResponse": {
        "type": "object",
        "properties": {
          "apiKey": {
            "allOf": [
              { "$ref": "#/components/schemas/ApiKey" },
              {
                "type": "object",
                "properties": { "key": { "type": "string" } },
                "required": ["key"]
              }
            ]
          }
        },
        "required": ["apiKey"]
      },
      "DeleteApiKeyResponse": {
        "type": "object",
        "properties": { "apiKey": { "$ref": "#/components/schemas/ApiKey" } },
        "required": ["apiKey"]
      },
      "EditApiKeyResponse": {
        "type": "object",
        "properties": { "apiKey": { "$ref": "#/components/schemas/ApiKey" } },
        "required": ["apiKey"]
      },
      "EditApiKeyRequest": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "enabled": { "type": "boolean" },
          "scopes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ApiKeyScope" }
          }
        }
      },
      "RetrieveCustomerBillingMeterUsageResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "billingId": { "type": "string" },
                "day": { "type": "string" },
                "totalBillingUsage": { "type": "string", "pattern": "^d+$" },
                "billingUsageName": { "type": "string" }
              },
              "required": [
                "billingId",
                "day",
                "totalBillingUsage",
                "billingUsageName"
              ]
            }
          }
        },
        "required": ["data"]
      },
      "CreateCustomerBillingMeterResponse": {
        "type": "object",
        "properties": {
          "billing": { "$ref": "#/components/schemas/CustomerBillingMeter" }
        },
        "required": ["billing"]
      },
      "CreateCustomerBillingMeterRequest": {
        "type": "object",
        "properties": {
          "totalCredits": {
            "type": "string",
            "pattern": "^\\d+$",
            "default": "0"
          },
          "allowOverages": { "type": "boolean", "default": false },
          "spendCap": { "type": "string", "pattern": "^\\d+$" },
          "externalMeterId": { "type": "string" },
          "workspaceId": { "type": "string" }
        },
        "required": ["externalMeterId", "workspaceId"]
      },
      "RefillCustomerBillingMeterResponse": {
        "type": "object",
        "properties": {
          "billing": { "$ref": "#/components/schemas/CustomerBillingMeter" }
        },
        "required": ["billing"]
      },
      "RefillCustomerBillingMeterRequest": {
        "type": "object",
        "properties": {
          "workspaceId": { "type": "string" },
          "externalMeterId": { "type": "string" },
          "refill": {
            "type": "integer",
            "minimum": 0,
            "exclusiveMinimum": true
          }
        },
        "required": ["workspaceId", "externalMeterId"]
      },
      "GetCustomerBillingMeterResponse": {
        "type": "object",
        "properties": {
          "billing": { "$ref": "#/components/schemas/CustomerBillingMeter" }
        },
        "required": ["billing"]
      },
      "MigrateApiKeyResponse": {
        "type": "object",
        "properties": {
          "apiKey": {
            "allOf": [
              { "$ref": "#/components/schemas/ApiKey" },
              {
                "type": "object",
                "properties": { "key": { "type": "string" } },
                "required": ["key"]
              }
            ]
          }
        },
        "required": ["apiKey"]
      },
      "MigrateApiKeyRequest": {
        "type": "object",
        "properties": {
          "key": { "type": "string" },
          "name": { "type": "string" },
          "workspaceId": { "type": "string" },
          "scopes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "representation": { "type": "string" },
                "create": { "type": "boolean" },
                "read": { "type": "boolean" },
                "update": { "type": "boolean" },
                "del": { "type": "boolean" }
              },
              "required": ["representation", "create", "read", "update", "del"]
            }
          },
          "enabled": { "type": "boolean" },
          "customerId": { "type": "string" },
          "metadata": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          }
        },
        "required": [
          "key",
          "name",
          "workspaceId",
          "scopes",
          "enabled",
          "customerId"
        ]
      }
    },
    "parameters": {}
  },
  "paths": {
    "/api/v1/workspace": {
      "post": {
        "operationId": "createWorkspace",
        "summary": "Create a workspace",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWorkspaceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateWorkspaceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "getWorkspace",
        "summary": "Retrieve a workspace",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveWorkspaceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}": {
      "get": {
        "operationId": "getWorkspaceById",
        "summary": "Retrieve a workspace",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveWorkspaceByIdResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateWorkspace",
        "summary": "Updates a workspace",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWorkspaceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdateWorkspaceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}/scopes": {
      "get": {
        "operationId": "getWorkspaceScopes",
        "summary": "Retrieve workspace scopes",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace scopes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveAllWorkspaceScopesResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}/scope": {
      "post": {
        "operationId": "createWorkspaceScopes",
        "summary": "Create a workspace scope",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWorkspaceScopeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateWorkspaceScopeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/api-key": {
      "post": {
        "operationId": "createApiKey",
        "summary": "Create an API key",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateApiKeyRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}/api-key": {
      "get": {
        "operationId": "getApiKeys",
        "summary": "Retrieve API keys for a workspace",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The API keys",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveApiKeysResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}/api-key/{akid}": {
      "get": {
        "operationId": "getApiKeyById",
        "summary": "Retrieve an API key by id",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": { "type": "string", "description": "The API key id." },
            "required": true,
            "name": "akid",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveApiKeyByIdResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteApiKey",
        "summary": "Deletes a key for a given workspace",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": { "type": "string", "description": "The API key id." },
            "required": true,
            "name": "akid",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The updated deleted key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "editApiKey",
        "summary": "Edit an API key",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": { "type": "string", "description": "The API key id." },
            "required": true,
            "name": "akid",
            "in": "path"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/EditApiKeyRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The edited key",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/EditApiKeyResponse" }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/api-key/verify": {
      "post": {
        "operationId": "verifyApiKey",
        "summary": "Verify a key for a given workspace",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/VerifyApiKeyRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The verification result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifyApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/api-key/record-usage": {
      "post": {
        "operationId": "recordApiKeyUsage",
        "summary": "Record API key usage",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordUsageApiKeyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The record usage result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordUsageApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/workspace/{id}/api-key/{akid}/rotate": {
      "post": {
        "operationId": "rotateApiKey",
        "summary": "Rotate a key for a given workspace",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": { "type": "string", "description": "The API key id." },
            "required": true,
            "name": "akid",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The newly rotated key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RotateApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/link-token": {
      "post": {
        "operationId": "generateLinkToken",
        "summary": "Generate a link token",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "customerId": { "type": "string" },
                  "workspaceId": { "type": "string" },
                  "externalBillingId": { "type": "string" }
                },
                "required": ["customerId", "workspaceId"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The generated link token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": { "type": "string" },
                    "expiresAt": {
                      "type": "integer",
                      "minimum": 0,
                      "exclusiveMinimum": true
                    }
                  },
                  "required": ["token", "expiresAt"]
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/link-token/{token}": {
      "get": {
        "operationId": "validateLinkToken",
        "summary": "Validate a link token",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The link token." },
            "required": true,
            "name": "token",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": { "type": "boolean" },
                    "expiresAt": {
                      "type": "integer",
                      "minimum": 0,
                      "exclusiveMinimum": true
                    },
                    "workspaceId": { "type": "string" },
                    "customerId": { "type": "string" },
                    "externalBillingId": { "type": "string" }
                  },
                  "required": [
                    "valid",
                    "expiresAt",
                    "workspaceId",
                    "customerId"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/usage/{bid}": {
      "get": {
        "operationId": "getBillingUsage",
        "summary": "Retrieve billing usage information for a given billing id",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The billing id." },
            "required": true,
            "name": "bid",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "The billing usage information",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RetrieveCustomerBillingMeterUsageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/customer-billing": {
      "post": {
        "operationId": "createCustomerBilling",
        "summary": "Create customer billing",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCustomerBillingMeterRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateCustomerBillingMeterResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "getCustomerBilling",
        "summary": "Retrieve customer billing",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "schema": { "type": "string", "description": "The workspace id." },
            "required": true,
            "name": "workspaceId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "The external meter id."
            },
            "required": true,
            "name": "externalMeterId",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Customer billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GetCustomerBillingMeterResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/customer-billing/refill": {
      "post": {
        "operationId": "refillBillingLimit",
        "summary": "Refill the billing limit",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RefillCustomerBillingMeterRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefillCustomerBillingMeterResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/api-key/migrate": {
      "post": {
        "operationId": "migrateApiKey",
        "summary": "Migrate an API key",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/MigrateApiKeyRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The migrated key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MigrateApiKeyResponse"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/jwt": {
      "post": {
        "operationId": "createJwt",
        "summary": "Create a JWT",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "payload": {
                    "type": "object",
                    "additionalProperties": { "type": "string" }
                  },
                  "aud": { "type": "string" },
                  "exp": {
                    "type": "integer",
                    "minimum": 0,
                    "exclusiveMinimum": true,
                    "default": 3600
                  }
                },
                "required": ["payload"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created JWT",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "jwt": { "type": "string" } },
                  "required": ["jwt"]
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/jwt/verify": {
      "post": {
        "operationId": "verifyJwt",
        "summary": "Verify a JWT",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jwt": { "type": "string" },
                  "rateLimitConfig": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "string" },
                      "limit": {
                        "type": "integer",
                        "minimum": 0,
                        "exclusiveMinimum": true
                      },
                      "interval": { "type": "string" }
                    },
                    "required": ["id", "limit", "interval"]
                  }
                },
                "required": ["jwt"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The verification result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": ["VALID", "INVALID"]
                    },
                    "payload": {
                      "type": "object",
                      "additionalProperties": { "type": "string" }
                    },
                    "aud": { "type": "string" },
                    "exp": {
                      "type": "integer",
                      "minimum": 0,
                      "exclusiveMinimum": true
                    }
                  },
                  "required": ["status", "payload", "exp"]
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  }
}
