{
  "openapi": "3.1.0",
  "info": {
    "title": "SuperbAPI Gateway",
    "version": "1.1.0",
    "description": "OpenAI-compatible AI gateway. One prepaid balance and one set of keys across many model families. Point any OpenAI SDK at the base URL and pass a SuperbAPI key. Independent aggregator; third-party model names are used nominatively to indicate routing.",
    "contact": {
      "url": "https://www.superbapi.com"
    }
  },
  "servers": [
    {
      "url": "https://www.superbapi.com/v1",
      "description": "OpenAI-compatible base URL"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/models": {
      "get": {
        "summary": "List callable models",
        "description": "Returns the models the authenticated key can call, in OpenAI list format. claude-* models additionally appear under an sb- alias usable anywhere the canonical ID is.",
        "operationId": "listModels",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "object": {
                            "type": "string",
                            "const": "model"
                          },
                          "owned_by": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completion. Usage draws down the prepaid wallet at the model's rate. Streaming (SSE) is supported via stream: true. Every model also accepts an 'sb-' alias (e.g. sb-claude-fable-5) for editors that reserve built-in model IDs; the gateway strips the prefix before routing.",
        "operationId": "createChatCompletion",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "examples": [
                      "claude-opus-4-8",
                      "sb-claude-fable-5"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "role",
                        "content"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible completion object",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "headers": {
              "x-request-id": {
                "description": "Unique id for this request; quote it in support tickets.",
                "schema": {
                  "type": "string"
                }
              },
              "x-superbapi-cost-usd": {
                "description": "USD charged for this call (non-streaming).",
                "schema": {
                  "type": "string"
                }
              },
              "x-superbapi-total-tokens": {
                "description": "Total tokens billed.",
                "schema": {
                  "type": "string"
                }
              },
              "x-superbapi-served-model": {
                "description": "The model the upstream actually served.",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Hourly request cap (trial credit accounts).",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Requests remaining in the current window.",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Seconds until the window resets.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "402": {
            "description": "Insufficient credit"
          },
          "429": {
            "description": "Rate limit exceeded (trial-credit accounts).",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/keys": {
      "post": {
        "summary": "Mint a scoped API key",
        "description": "Provisioning endpoint. Authenticate with a provisioning token (not a regular API key). Returns the new key value once.",
        "operationId": "provisionApiKey",
        "security": [
          {
            "provisioningAuth": []
          }
        ],
        "servers": [
          {
            "url": "https://www.superbapi.com"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "allowedModels": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "routeScope": {
                    "type": "string"
                  },
                  "budgetLimit": {
                    "type": [
                      "number",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created key (value shown once)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    },
                    "key": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List provisioned keys",
        "operationId": "listProvisionedKeys",
        "security": [
          {
            "provisioningAuth": []
          }
        ],
        "servers": [
          {
            "url": "https://www.superbapi.com"
          }
        ],
        "responses": {
          "200": {
            "description": "Key list (values not revealed)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/keys/{id}": {
      "delete": {
        "summary": "Revoke a provisioned key",
        "operationId": "revokeProvisionedKey",
        "security": [
          {
            "provisioningAuth": []
          }
        ],
        "servers": [
          {
            "url": "https://www.superbapi.com"
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/credits": {
      "get": {
        "summary": "Credit balance & usage summary (OpenRouter-compatible).",
        "description": "Returns total credits, used credits, and remaining balance for the authenticated key.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Credit summary"
          },
          "401": {
            "description": "Invalid API key"
          }
        }
      }
    },
    "/api/api-keys/{id}/rotate": {
      "post": {
        "summary": "Rotate a key secret in place",
        "description": "Issues a new secret for the key (same label/scope/budget); the old secret stops working immediately. New value returned once.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The key with its new one-time value."
          },
          "404": {
            "description": "Key not found"
          },
          "409": {
            "description": "Key is not active"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your SuperbAPI key. Send as: Authorization: Bearer YOUR_API_KEY"
      },
      "provisioningAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "A provisioning token (manages keys; cannot call models). Send as: Authorization: Bearer YOUR_PROVISIONING_TOKEN"
      }
    }
  }
}