{
  "openapi": "3.1.0",
  "info": {
    "title": "Seracade API",
    "version": "1.1.0",
    "description": "Seracade is a drop-in OpenAI-compatible routing proxy for AI agent teams. It exposes six named capabilities: Call (every inference request, addressable and replayable), Step (sub-Call routing context inside agent trajectories, identified by optional headers), Quality Score (calibrated, version-stamped quality fingerprint per Call), Routing Decision (the unit of the routing table: task_type and Quality Gate threshold mapped to a candidate model set), Counterfactual Replay (re-run any historical Call against alternate models, returning counterfactual cost and Score), and Quality Gate (customer-set policy constraining the routing table). BYOK. 15% of the absolute price difference per routed Call (and per Replay), in either direction, free during a one-time $500 lifetime trial.",
    "contact": {
      "name": "Seracade",
      "url": "https://seracade.com",
      "email": "alex@seracade.com"
    },
    "x-audience": "Primary: AI agent teams (CrewAI, LangGraph, AutoGen, custom). Secondary: SaaS with embedded AI features. Tertiary: customer support automation. All paying per token, spending $2K+/mo on inference.",
    "x-product-category": "LLM routing proxy with empirical per-task quality measurement",
    "x-not-for": "Consumer applications, individual users, standalone chat, flat-fee subscription users (Claude Max, ChatGPT Plus)",
    "x-capabilities": [
      "Call",
      "Step",
      "Quality Score",
      "Routing Decision",
      "Counterfactual Replay",
      "Quality Gate"
    ],
    "x-call-id-header": "Every routed /chat/completions response carries X-Seracade-Call-Id, X-Seracade-Calibration-Version, and X-Seracade-Score-Disclaimer. The Call ID is the input to /v1/replay.",
    "x-cross-shape": "Seracade also accepts native Anthropic (/v1/messages), Google (/v1beta/...), and xAI request shapes. When routing substitutes the model on a non-OpenAI shape, the response is translated back to the native shape so the customer SDK parses cleanly. Coverage: non-streaming text, non-streaming tool calls, streaming text, streaming tool calls. Multimodal inputs and provider-specific features pass through unchanged. Opt-in per customer: POST /api/cross-shape-routing { enabled: true }. Routed responses carry X-Seracade-Cross-Shape: <provider>."
  },
  "servers": [
    {
      "url": "https://seracade.com/v1",
      "description": "OpenAI-compatible proxy endpoint"
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "summary": "Route a Call to the frontier-optimal model for the task at the customer's Quality Gate",
        "description": "Drop-in replacement for OpenAI /v1/chat/completions. Seracade classifies the request by task type, looks up the Routing Decision at the customer's active Quality Gate, and routes to the point on the price-performance frontier that meets quality, up or down based on evidence. Requires routing to be active (activate routing first). Optional Step headers (X-Seracade-Step-Id, X-Seracade-Parent-Call-Id, X-Seracade-Trace-Id) are stripped before the upstream provider sees the request and persisted as opaque tags on the Call record.",
        "tags": [
          "Call"
        ],
        "parameters": [
          {
            "name": "X-Seracade-Step-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Opaque identifier for the Step within an agent trajectory. Persisted on the Call record. Stripped before upstream forwarding."
          },
          {
            "name": "X-Seracade-Parent-Call-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "ID of the upstream Call that produced this Step's input. Persisted on the Call record. Stripped before upstream forwarding."
          },
          {
            "name": "X-Seracade-Trace-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Opaque identifier for the full agent run. Persisted on the Call record. Stripped before upstream forwarding."
          }
        ],
        "responses": {
          "200": {
            "description": "OpenAI-format chat completion. Response metadata (`x-seracade-*` headers) carries the routing evidence: model_used, model_considered, route_reason, calibration_version, sample_size, and 'subject to recalibration' disclaimer."
          }
        }
      }
    },
    "/replay": {
      "post": {
        "summary": "Counterfactual Replay of a historical Call against alternate models",
        "description": "Re-runs the specified historical Call against the candidate models and returns counterfactual cost and Quality Score per candidate, version-stamped. Use to validate a Routing Decision, evaluate a candidate model before promoting it, or build cost-regression tests in CI. Replay output is private to the requesting customer and is not for redistribution. Pricing matches routed Calls (15% of the absolute price difference per Replay, free during a one-time $500 lifetime trial).",
        "tags": [
          "Counterfactual Replay"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "call_id",
                  "candidate_models"
                ],
                "properties": {
                  "call_id": {
                    "type": "string",
                    "description": "ID of the historical Call to replay."
                  },
                  "candidate_models": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "maxItems": 16,
                    "description": "Candidate models to replay against. Up to 16 per request."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replay result with counterfactual cost and Quality Score per candidate, version-stamped.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "call_id": {
                      "type": "string"
                    },
                    "calibration_version": {
                      "type": "string"
                    },
                    "disclaimer": {
                      "type": "string",
                      "description": "Subject to recalibration. Not for redistribution. Customer-private."
                    },
                    "replays": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "model": {
                            "type": "string"
                          },
                          "cost_usd": {
                            "type": "number"
                          },
                          "quality_score": {
                            "type": "number",
                            "nullable": true,
                            "description": "Null if below the per-customer suppression threshold."
                          },
                          "sample_size": {
                            "type": "integer"
                          },
                          "route_reason": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/auth/send-magic-link": {
      "post": {
        "summary": "Send a one-time sign-in link by email",
        "description": "Signs a 15-minute HMAC-SHA256 token tied to the supplied email and emails it as a /auth/verify link. Always returns 200 to prevent user enumeration.",
        "tags": [
          "Auth"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "next": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email queued (or appeared queued for unknown emails)."
          }
        }
      }
    },
    "/auth/verify": {
      "get": {
        "summary": "Validate a magic link and set the session cookie",
        "description": "Validates the HMAC signature, TTL, and replay nonce of the supplied token. On success sets a 30-day HttpOnly Secure SameSite=Strict cookie scoped to seracade.com and redirects to the requested next URL. On failure redirects to /login with an error code.",
        "tags": [
          "Auth"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to /dashboard or /login depending on validity."
          }
        }
      }
    },
    "/auth/logout": {
      "post": {
        "summary": "Clear the session cookie",
        "tags": [
          "Auth"
        ],
        "responses": {
          "200": {
            "description": "Cookie cleared."
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "summary": "Read the signed-in email, if any",
        "tags": [
          "Auth"
        ],
        "responses": {
          "200": {
            "description": "{ signed_in: boolean, email?: string }"
          }
        }
      }
    },
    "/dashboard": {
      "get": {
        "summary": "Read the customer's dashboard hub data",
        "description": "Returns calls logged, report URL (if available), routing-active status, and the URLs for every customer-facing capability page. Authenticated by the same short audit token. The dashboard page itself lives at `https://seracade.com/dashboard/<token>`.",
        "tags": [
          "Dashboard"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 32
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Hub data plus URL set."
          },
          "404": {
            "description": "Token not found or expired."
          }
        }
      }
    },
    "/dashboard/rotate": {
      "post": {
        "summary": "Rotate the customer's dashboard token",
        "description": "Mints a fresh short token and invalidates the previous one immediately. Use when a dashboard URL has been shared or leaked unexpectedly.",
        "tags": [
          "Dashboard"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "New token plus the new dashboard URL.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "new_token": {
                      "type": "string"
                    },
                    "dashboard_url": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Old token not found or expired."
          }
        }
      }
    },
    "/routing-table": {
      "get": {
        "summary": "Read the customer's active routing table",
        "description": "Read-only view of the customer's Routing Decisions, version-stamped. Authenticated by a short audit token (the same one served at `/audit/<token>`); the token grants read access to derived state only and never the power of a provider API key. Browser-friendly: rendered at `https://seracade.com/routing-table/<token>`.",
        "tags": [
          "Routing Decision"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 32
            },
            "description": "Short audit token issued during audit registration. Resolves server-side to the customer record."
          }
        ],
        "responses": {
          "200": {
            "description": "Active routing table joined with frontier scores and the customer's Quality Gates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "calibration_version": {
                      "type": "string"
                    },
                    "disclaimer": {
                      "type": "string"
                    },
                    "generated_at": {
                      "type": "string",
                      "nullable": true
                    },
                    "routing_active": {
                      "type": "boolean"
                    },
                    "decisions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "task_type": {
                            "type": "string"
                          },
                          "model": {
                            "type": "string"
                          },
                          "quality_score": {
                            "type": "number",
                            "nullable": true,
                            "description": "Null if sample size is below the per-customer suppression threshold."
                          },
                          "sample_size": {
                            "type": "integer"
                          },
                          "on_frontier": {
                            "type": "boolean"
                          },
                          "active_gate_minimum_score": {
                            "type": "number",
                            "nullable": true
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Token not found or expired."
          }
        }
      }
    },
    "/gates": {
      "get": {
        "summary": "Read the customer's active Quality Gates",
        "description": "Returns the (task_type → minimum_score) Gates currently in force on the customer account. Gates constrain the routing table relative to the original model: the gate binds only when benchmark evidence for both the original model and the candidate is available, holding the Call on the original model when the candidate's measured quality is below the gate fraction of the original's; when either side's benchmark evidence is absent, the relative gate admits the candidate and the per-call quality gate governs. Response is version-stamped.",
        "tags": [
          "Quality Gate"
        ],
        "responses": {
          "200": {
            "description": "Active Gates plus calibration_version and disclaimer.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "calibration_version": {
                      "type": "string"
                    },
                    "disclaimer": {
                      "type": "string"
                    },
                    "gates": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "minimum_score": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 1
                          },
                          "set_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Upsert one or more Quality Gates",
        "description": "Sets or replaces Gates by task_type. Each entry is a minimum_score in [0, 1]. Valid task types: extraction, classification, function_calling, summarization, rewriting, qa_rag, reasoning, coding, agent_orchestration, other.",
        "tags": [
          "Quality Gate"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "gates"
                ],
                "properties": {
                  "gates": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "required": [
                        "minimum_score"
                      ],
                      "properties": {
                        "minimum_score": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "All active Gates after the upsert, plus calibration_version and disclaimer."
          }
        }
      },
      "delete": {
        "summary": "Remove one Gate or clear all Gates",
        "description": "Body { task_type } removes a single Gate; an empty body clears every Gate on the account.",
        "tags": [
          "Quality Gate"
        ]
      }
    },
    "/mcp": {
      "post": {
        "summary": "MCP protocol endpoint",
        "description": "Model Context Protocol endpoint. Exposes seracade_route (Call routing) and seracade (account management) tools.",
        "tags": [
          "MCP"
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Call",
      "description": "Every inference request through Seracade is a Call: addressable, metadata-rich, replayable."
    },
    {
      "name": "Counterfactual Replay",
      "description": "Re-run any historical Call against alternate models; counterfactual cost and Quality Score per candidate."
    },
    {
      "name": "Routing Decision",
      "description": "The unit of the routing table: (task_type, Quality Gate threshold) mapped to the candidate model that meets it."
    },
    {
      "name": "Quality Gate",
      "description": "Customer-set policy that constrains the routing table. Seracade reports each task type's measured pass rate against its active Gate with a Wilson 95% confidence interval."
    },
    {
      "name": "Dashboard",
      "description": "Token-authenticated hub that reads the customer's current state across every capability."
    },
    {
      "name": "Auth",
      "description": "Magic-link sign-in. Email + 15-minute one-time link sets a 30-day HttpOnly Secure SameSite=Strict session cookie. No passwords."
    },
    {
      "name": "MCP",
      "description": "Model Context Protocol tools for agent integration."
    }
  ]
}