{
  "openapi": "3.1.0",
  "info": {
    "title": "ZeroCredit AI API",
    "version": "1.0.0",
    "summary": "One AI layer. Every model. Automatically optimized.",
    "description": "OpenAI-compatible HTTP API for ZeroCredit AI. Point any OpenAI client at this base URL with a ZeroCredit API token to route chat completions, embeddings and image generation across providers with automatic cost optimization.",
    "contact": {
      "name": "ZeroCredit AI",
      "url": "https://zerocreditai.com/contact",
      "email": "founder@zerocreditai.com"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://zerocreditai.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://zerocreditai.com",
      "description": "Production"
    }
  ],
  "externalDocs": {
    "description": "Developer documentation",
    "url": "https://zerocreditai.com/docs"
  },
  "tags": [
    {
      "name": "Discovery",
      "description": "Unauthenticated metadata about the service and model catalog."
    },
    {
      "name": "Chat",
      "description": "OpenAI-compatible chat completions."
    },
    {
      "name": "Embeddings",
      "description": "Vector embeddings."
    },
    {
      "name": "Images",
      "description": "Image generation."
    }
  ],
  "paths": {
    "/api/public/v1/status": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "operationId": "getStatus",
        "summary": "Service status",
        "description": "Unauthenticated liveness and capability summary for agents evaluating the API.",
        "security": [],
        "responses": {
          "200": {
            "description": "Service status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/catalog": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "operationId": "getCatalog",
        "summary": "Public model catalog",
        "description": "Unauthenticated catalog of routable models with provider, context window and public list prices per 1K tokens.",
        "security": [],
        "responses": {
          "200": {
            "description": "Model catalog",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Catalog"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/sandbox/chat/completions": {
      "post": {
        "tags": [
          "Discovery"
        ],
        "operationId": "createSandboxChatCompletion",
        "summary": "Sandbox chat completion",
        "description": "Unauthenticated sandbox that validates the live chat completion request shape and returns a deterministic, clearly labelled canned response. No provider is called, nothing is billed, and no usage is recorded.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sandbox completion, or a text/event-stream when stream is true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/models": {
      "get": {
        "tags": [
          "Discovery"
        ],
        "operationId": "listModels",
        "summary": "List models available to the caller",
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid or revoked credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completion. Capabilities (vision, tool calling, structured output, web search) are detected from the request and routed to a compatible provider automatically.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion, or a text/event-stream when stream is true",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid or revoked credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Requested model does not exist",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit or provider quota exhausted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Every compatible provider failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/embeddings": {
      "post": {
        "tags": [
          "Embeddings"
        ],
        "operationId": "createEmbedding",
        "summary": "Create embeddings",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmbeddingRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Embedding vectors",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmbeddingList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid or revoked credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Provider call failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/v1/images/generations": {
      "post": {
        "tags": [
          "Images"
        ],
        "operationId": "createImage",
        "summary": "Generate an image",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated images",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid or revoked credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Provider call failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ZeroCreditApiToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "zc_<token>",
        "description": "ZeroCredit API token created in the app under API Keys. Scoped to one organization, and optionally to one project for cost allocation."
      },
      "OAuth2": {
        "type": "oauth2",
        "description": "OAuth 2.0 authorization code flow with PKCE and dynamic client registration, used by agents and MCP clients. Metadata: /.well-known/oauth-authorization-server. Tokens are signed by https://xmtwspbebfezikkmjjmr.supabase.co/auth/v1.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://zerocreditai.com/api/public/oauth/authorize",
            "tokenUrl": "https://zerocreditai.com/api/public/oauth/token",
            "refreshUrl": "https://zerocreditai.com/api/public/oauth/token",
            "scopes": {
              "openid": "Confirm the end user's identity.",
              "profile": "Read the end user's basic profile (display name).",
              "email": "Read the end user's email address.",
              "offline_access": "Obtain a refresh token for long-running agents."
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message"
            ],
            "properties": {
              "message": {
                "type": "string",
                "description": "Human-readable explanation."
              },
              "type": {
                "type": "string",
                "description": "Error family, e.g. invalid_request_error."
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Stable machine-readable error code."
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Offending request field, when applicable."
              },
              "hint": {
                "type": "string",
                "description": "Suggested resolution."
              }
            }
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "status"
          },
          "status": {
            "type": "string",
            "enum": [
              "ok"
            ]
          },
          "api_version": {
            "type": "string"
          },
          "openai_compatible": {
            "type": "boolean"
          },
          "base_url": {
            "type": "string",
            "format": "uri"
          },
          "endpoints": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "documentation_url": {
            "type": "string",
            "format": "uri"
          },
          "openapi_url": {
            "type": "string",
            "format": "uri"
          },
          "mcp_url": {
            "type": "string",
            "format": "uri"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Catalog": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "display_name": {
                  "type": "string"
                },
                "provider": {
                  "type": "string"
                },
                "context_window": {
                  "type": "integer"
                },
                "capabilities": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "input_cost_per_1k_usd": {
                  "type": "number"
                },
                "output_cost_per_1k_usd": {
                  "type": "number"
                }
              }
            }
          }
        }
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "object": {
                  "type": "string",
                  "const": "model"
                },
                "created": {
                  "type": "integer"
                },
                "owned_by": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": [
          "role"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant",
              "tool"
            ]
          },
          "content": {
            "description": "String, or an array of content parts for text, images and files.",
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "tool_call_id": {
            "type": "string"
          },
          "tool_calls": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "A catalog model id, or a routing alias: zerocredit-auto, zerocredit-cheapest, zerocredit-fastest, zerocredit-balanced, zerocredit-premium."
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "response_format": {
            "type": "object",
            "description": "OpenAI response_format, including json_schema."
          },
          "web_search_options": {
            "type": "object",
            "description": "Enables provider-native web search with citations."
          },
          "project_id": {
            "type": "string",
            "format": "uuid",
            "description": "Cost-allocation project in the caller's organization."
          }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "const": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          },
          "zerocredit": {
            "type": "object",
            "description": "ZeroCredit routing and accounting metadata.",
            "properties": {
              "provider": {
                "type": "string"
              },
              "cost_usd": {
                "type": "number"
              },
              "savings_usd": {
                "type": "number"
              },
              "cache_hit": {
                "type": "boolean"
              },
              "capability": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "execution_path": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        }
      },
      "EmbeddingRequest": {
        "type": "object",
        "required": [
          "model",
          "input"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "project_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "EmbeddingList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "list"
          },
          "model": {
            "type": "string"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "object": {
                  "type": "string",
                  "const": "embedding"
                },
                "index": {
                  "type": "integer"
                },
                "embedding": {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                }
              }
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "ImageRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "prompt": {
            "type": "string"
          },
          "n": {
            "type": "integer",
            "default": 1
          },
          "size": {
            "type": "string"
          },
          "project_id": {
            "type": "string",
            "format": "uuid"
          }
        }
      },
      "ImageList": {
        "type": "object",
        "properties": {
          "created": {
            "type": "integer"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "ZeroCreditApiToken": []
    },
    {
      "OAuth2": [
        "openid",
        "profile",
        "email",
        "offline_access"
      ]
    }
  ]
}