{
  "openapi": "3.1.0",
  "info": {
    "title": "ProxyLLM API",
    "version": "1.0.0",
    "description": "OpenAI-compatible LLM gateway. Inference endpoints accept a pllm_ routing key in the Authorization header (Bearer optional) and ride the key's provider lanes with fallback. Management endpoints accept an sk_/rk_ account token. Agents can create an account autonomously: https://proxyllm.ai/auth.md",
    "contact": {
      "url": "https://proxyllm.ai/docs/api"
    }
  },
  "servers": [
    {
      "url": "https://api.proxyllm.ai"
    }
  ],
  "security": [],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "OpenAI-compatible chat completions",
        "description": "Same request and response shapes as OpenAI's /v1/chat/completions, including streaming. The routing key's lanes decide which provider serves.",
        "security": [
          {
            "routingKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Model name, or a Codex tier alias (flagship, mini) on Codex-backed keys. GET /v1/models lists what this key can reach."
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-shaped completion (or SSE stream)."
          },
          "401": {
            "description": "Missing or invalid routing key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Routing key over its monthly budget.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "summary": "OpenAI-compatible Responses API",
        "security": [
          {
            "routingKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-shaped response (or SSE stream)."
          },
          "401": {
            "description": "Missing or invalid routing key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List models (no auth required)",
        "description": "OpenAI-shaped model list. With a routing key it reflects that key's lanes (including the live Codex catalog); without one it lists the general catalog.",
        "responses": {
          "200": {
            "description": "OpenAI-shaped model list."
          }
        }
      }
    },
    "/v1/key": {
      "get": {
        "summary": "Introspect the calling routing key",
        "description": "Answers with the key's lanes (provider, models, whether a Codex subscription backs it), mode, and budget state. Authed by the routing key itself.",
        "security": [
          {
            "routingKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Routing key introspection object."
          },
          "401": {
            "description": "Missing or invalid routing key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/organizations/me": {
      "get": {
        "summary": "Account state (works while unpaid)",
        "description": "The one management endpoint an unpaid account may keep calling. While plan is \"free\" the response carries a payment block (checkout_url, price_usd, account_expires_at) and a relay-ready message; agents poll this until plan is \"pro\".",
        "security": [
          {
            "accountToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Account state, plus payment block while unpaid."
          },
          "401": {
            "description": "Missing or invalid account token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Account expired (48h unpaid window passed).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/organizations/routing-keys": {
      "get": {
        "summary": "List routing keys",
        "description": "Add ?include=lanes to also receive the caller's wireable lanes (codex_sessions, bridges, saved provider credentials) with the ids provider chains reference.",
        "security": [
          {
            "accountToken": []
          }
        ],
        "parameters": [
          {
            "name": "include",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "lanes"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "routing_keys array, plus lanes if requested."
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "410": {
            "description": "Account expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a routing key (optionally wired)",
        "description": "Returns raw_key (pllm_) exactly once. Pass mode and a providers array to wire the provider chain in the same call; omit providers to create bare and wire later via PATCH.",
        "security": [
          {
            "accountToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "fallback",
                      "classifier"
                    ]
                  },
                  "monthly_budget_usd": {
                    "type": "number"
                  },
                  "providers": {
                    "type": "array",
                    "maxItems": 5,
                    "items": {
                      "$ref": "#/components/schemas/ProviderLane"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "routing_key plus one-time raw_key."
          },
          "400": {
            "description": "Invalid config or a referenced lane is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        }
      },
      "patch": {
        "summary": "Update or rewire a routing key",
        "description": "?id=<routing_key_id>. Accepts label, monthly_budget_usd, revoked, regenerate, and a providers array (with mode) to replace the chain.",
        "security": [
          {
            "accountToken": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated routing_key."
          },
          "400": {
            "description": "Invalid config or a referenced lane is not yours.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        }
      }
    },
    "/v1/organizations/bridges": {
      "get": {
        "summary": "List Claude Code bridges",
        "security": [
          {
            "accountToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "bridges array."
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        }
      },
      "post": {
        "summary": "Register a self-hosted Claude Code bridge",
        "security": [
          {
            "accountToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Registered bridge."
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        }
      }
    },
    "/v1/organizations/usage": {
      "get": {
        "summary": "30-day usage summary",
        "security": [
          {
            "accountToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage rollup."
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "routingKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "pllm_ routing key. The Bearer prefix is optional."
      },
      "accountToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "sk_ (read+write) or rk_ (read-only) account token. Agents obtain one via https://proxyllm.ai/auth.md"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      },
      "ProviderLane": {
        "type": "object",
        "required": [
          "provider"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "description": "codex, bridge, or an API-key provider (openai, anthropic, openrouter, gemini, deepseek, xai, groq, mistral, together, fireworks, cerebras, perplexity, cohere)."
          },
          "model": {
            "type": "string",
            "nullable": true
          },
          "credential_id": {
            "type": "string",
            "nullable": true,
            "description": "Required for API-key providers."
          },
          "codex_session_id": {
            "type": "string",
            "nullable": true,
            "description": "Required when provider is codex."
          },
          "bridge_instance_id": {
            "type": "string",
            "nullable": true,
            "description": "Required when provider is bridge."
          }
        }
      },
      "PaymentBlock": {
        "type": "object",
        "properties": {
          "checkout_url": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "account_expires_at": {
            "type": "string",
            "nullable": true,
            "description": "When an unpaid agent-created account is removed (48h after signup)."
          },
          "poll": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "PaymentRequired": {
        "description": "No active membership. The body carries code=payment_required, a payment block (checkout_url, price_usd, account_expires_at), and a message written to be relayed to the account's human operator. Poll GET /v1/organizations/me until plan is \"pro\".",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                },
                "code": {
                  "type": "string"
                },
                "payment": {
                  "$ref": "#/components/schemas/PaymentBlock"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {},
  "x-agent-signup": {
    "description": "Account creation for agents (email OTP, no captcha). Both POST application/json.",
    "signup": {
      "url": "https://proxyllm.ai/api/auth?action=agent-signup",
      "body": {
        "email": "operator@example.com",
        "source": "optional-slug"
      }
    },
    "verify": {
      "url": "https://proxyllm.ai/api/auth?action=agent-verify",
      "body": {
        "email": "operator@example.com",
        "code": "123456"
      },
      "returns": "account_token (sk_, shown once) plus payment block while unpaid"
    },
    "manifest": "https://proxyllm.ai/auth.md"
  }
}