{
  "components": {
    "headers": {
      "RetryAfter": {
        "description": "Seconds to wait before a retry; always equal to `error.retry_after` when the body carries one.",
        "schema": {
          "minimum": 1,
          "type": "integer"
        }
      },
      "XPortalImagesError": {
        "description": "On a refusal by the images authorizer (`model_not_allowed`, `account_suspended`, `insufficient_balance`): the authorizer's code, equal to `error.code`. The worker's own 403 `image_identity_required` (after a successful authorization) carries no such header.",
        "schema": {
          "type": "string"
        }
      },
      "XPortalRunId": {
        "description": "The durable run id (`resp_` + 40 hex): the key for every retrieval and resume.",
        "schema": {
          "pattern": "^resp_[a-f0-9]{40}$",
          "type": "string"
        }
      },
      "XPortalRunRetention": {
        "description": "The retention rule: result retrieval for 86400 s after the run reaches a recorded terminal state; the status route names the exact expiry once known.",
        "schema": {
          "enum": [
            "terminal+86400"
          ],
          "type": "string"
        }
      },
      "XPortalRunStorageProfile": {
        "description": "The admitted failure scope of the durable store: `process` survives reader, relay and executor loss, not the host; `host` is not qualified today.",
        "schema": {
          "enum": [
            "process",
            "host"
          ],
          "type": "string"
        }
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "description": "Required for every durable creation (`/v1/responses`, or chat with `X-Portal-Durable: 1`): a printable key of at most 200 characters, saved before the request and reused if the reply is lost; reusing it with a different request answers 409 `idempotency_conflict`. Scoped to the account.",
        "in": "header",
        "name": "Idempotency-Key",
        "required": false,
        "schema": {
          "maxLength": 200,
          "minLength": 1,
          "pattern": "^[\\x21-\\x7e]{1,200}$",
          "type": "string"
        }
      },
      "IdempotencyKeyRequired": {
        "description": "Required on `POST /v1/responses` — checked before the body is read; absent or malformed answers 400 `invalid_idempotency_key`. Required for every durable creation (`/v1/responses`, or chat with `X-Portal-Durable: 1`): a printable key of at most 200 characters, saved before the request and reused if the reply is lost; reusing it with a different request answers 409 `idempotency_conflict`. Scoped to the account.",
        "in": "header",
        "name": "Idempotency-Key",
        "required": true,
        "schema": {
          "maxLength": 200,
          "minLength": 1,
          "pattern": "^[\\x21-\\x7e]{1,200}$",
          "type": "string"
        }
      },
      "LastEventID": {
        "description": "The SSE reconnect cursor (WHATWG). Both cursors (`starting_after` and `Last-Event-ID`) are validated: an invalid value answers 400 `invalid_cursor` even beside a valid one, and when both are valid the greater sequence wins.",
        "in": "header",
        "name": "Last-Event-ID",
        "required": false,
        "schema": {
          "pattern": "^(0|[1-9][0-9]*)$",
          "type": "string"
        }
      },
      "XPortalDurable": {
        "description": "`1` opts a chat completion into the durable route on an admitted account; it grants no account privilege. The body must then satisfy `DurableChatCompletionRequest`.",
        "in": "header",
        "name": "X-Portal-Durable",
        "required": false,
        "schema": {
          "enum": [
            "1"
          ],
          "type": "string"
        }
      },
      "XPortalTool": {
        "description": "A direct Portal tool call (`web_search`, `fetch_page`, `google_news`) with exactly one user message of JSON arguments; `stream` must be false.",
        "in": "header",
        "name": "X-Portal-Tool",
        "required": false,
        "schema": {
          "enum": [
            "web_search",
            "fetch_page",
            "web_fetch",
            "google_news"
          ],
          "type": "string"
        }
      },
      "format": {
        "description": "The run's original wire format; a chat-completions run must say so (`run_format_mismatch` otherwise).",
        "in": "query",
        "name": "format",
        "required": false,
        "schema": {
          "enum": [
            "responses",
            "chat.completions"
          ],
          "type": "string"
        }
      },
      "starting_after": {
        "description": "Exclusive resume cursor: the `sequence_number` of the last complete event processed; omit if none arrived. Both cursors (`starting_after` and `Last-Event-ID`) are validated: an invalid value answers 400 `invalid_cursor` even beside a valid one, and when both are valid the greater sequence wins.",
        "in": "query",
        "name": "starting_after",
        "required": false,
        "schema": {
          "minimum": 0,
          "type": "integer"
        }
      },
      "stream": {
        "description": "`true` resumes the event stream of a run created with `stream: true`; absent, a GET answers the status object or the completed result. Creation takes `stream` in the JSON body, not here.",
        "in": "query",
        "name": "stream",
        "required": false,
        "schema": {
          "type": "boolean"
        }
      }
    },
    "schemas": {
      "Capabilities": {
        "additionalProperties": true,
        "type": "object"
      },
      "ChatCompletion": {
        "additionalProperties": true,
        "properties": {
          "choices": {
            "items": {
              "properties": {
                "finish_reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "index": {
                  "type": "integer"
                },
                "message": {
                  "properties": {
                    "content": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "reasoning_content": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "tool_calls": {
                      "items": {
                        "$ref": "#/components/schemas/ToolCall"
                      },
                      "type": "array"
                    }
                  },
                  "type": "object"
                }
              },
              "type": "object"
            },
            "type": "array"
          },
          "created": {
            "type": "integer"
          },
          "id": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "object": {
            "enum": [
              "chat.completion"
            ],
            "type": "string"
          },
          "system_fingerprint": {
            "type": "string"
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        },
        "required": [
          "id",
          "object",
          "created",
          "model",
          "choices"
        ],
        "type": "object"
      },
      "ChatCompletionChunk": {
        "additionalProperties": true,
        "properties": {
          "choices": {
            "items": {
              "properties": {
                "delta": {
                  "additionalProperties": true,
                  "properties": {
                    "content": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "reasoning_content": {
                      "type": "string"
                    },
                    "role": {
                      "type": "string"
                    },
                    "tool_calls": {
                      "items": {
                        "additionalProperties": true,
                        "type": "object"
                      },
                      "type": "array"
                    }
                  },
                  "type": "object"
                },
                "finish_reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "index": {
                  "type": "integer"
                }
              },
              "type": "object"
            },
            "type": "array"
          },
          "created": {
            "type": "integer"
          },
          "error": {
            "additionalProperties": true,
            "description": "An error frame on a stream that failed after its headers were committed (the same body a fresh request would get as HTTP `status`).",
            "type": "object"
          },
          "id": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "object": {
            "enum": [
              "chat.completion.chunk"
            ],
            "type": "string"
          },
          "usage": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Usage"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "object",
          "created",
          "model",
          "choices"
        ],
        "type": "object"
      },
      "ChatCompletionRequest": {
        "additionalProperties": true,
        "description": "The native chat shape (OpenAI-compatible; unknown fields are passed through).",
        "properties": {
          "background": {
            "description": "With `X-Portal-Durable: 1`: a background durable run.",
            "type": "boolean"
          },
          "max_completion_tokens": {
            "minimum": 1,
            "type": "integer"
          },
          "max_tokens": {
            "description": "For the JSON formats: a visible-output delivery limit (cl100k_base); below the schema's floor the call answers 400 `output_limit_exceeded` naming `floor_tokens` before any model runs.",
            "minimum": 1,
            "type": "integer"
          },
          "messages": {
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            },
            "minItems": 1,
            "type": "array"
          },
          "model": {
            "description": "An exact id returned by `GET /v1/models` for this key; the id selects the route and the reasoning level.",
            "type": "string"
          },
          "n": {
            "enum": [
              1
            ],
            "type": "integer"
          },
          "parallel_tool_calls": {
            "type": "boolean"
          },
          "reasoning_effort": {
            "description": "Honored where the route supports it; a model id that carries its own level (the `-<level>-fast` ids a key may list) wins over this field.",
            "enum": [
              "none",
              "minimal",
              "low",
              "medium",
              "high",
              "xhigh",
              "max"
            ],
            "type": "string"
          },
          "response_format": {
            "$ref": "#/components/schemas/ResponseFormat"
          },
          "store": {
            "type": "boolean"
          },
          "stream": {
            "default": false,
            "type": "boolean"
          },
          "stream_options": {
            "properties": {
              "include_usage": {
                "type": "boolean"
              }
            },
            "type": "object"
          },
          "temperature": {
            "type": "number"
          },
          "tool_choice": {
            "oneOf": [
              {
                "enum": [
                  "auto",
                  "none",
                  "required"
                ],
                "type": "string"
              },
              {
                "additionalProperties": true,
                "type": "object"
              }
            ]
          },
          "tools": {
            "description": "Client function tools; an empty list opts into Portal's automatic web research on eligible routes.",
            "items": {
              "$ref": "#/components/schemas/Tool"
            },
            "type": "array"
          },
          "user": {
            "type": "string"
          }
        },
        "required": [
          "model",
          "messages"
        ],
        "type": "object"
      },
      "ChatMessage": {
        "properties": {
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              },
              {
                "items": {
                  "properties": {
                    "text": {
                      "type": "string"
                    },
                    "type": {
                      "enum": [
                        "text"
                      ],
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "text"
                  ],
                  "type": "object"
                },
                "type": "array"
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "role": {
            "enum": [
              "system",
              "developer",
              "user",
              "assistant",
              "tool"
            ],
            "type": "string"
          },
          "tool_call_id": {
            "type": "string"
          },
          "tool_calls": {
            "items": {
              "$ref": "#/components/schemas/ToolCall"
            },
            "type": "array"
          }
        },
        "required": [
          "role"
        ],
        "type": "object"
      },
      "DurableChatCompletionRequest": {
        "additionalProperties": false,
        "description": "The body of a chat completion sent with `X-Portal-Durable: 1`: the relay's allowlist, exactly — a field outside it answers 400 `unsupported_parameter`; `store: false` answers `unsupported_store`.",
        "if": {
          "properties": {
            "tools": {
              "maxItems": 0
            }
          },
          "required": [
            "tools"
          ]
        },
        "properties": {
          "background": {
            "description": "`true` for a background run; `false`/absent keeps the connection and retains replay through the idempotency key.",
            "type": "boolean"
          },
          "max_completion_tokens": {
            "minimum": 1,
            "type": "integer"
          },
          "max_tokens": {
            "minimum": 1,
            "type": "integer"
          },
          "messages": {
            "description": "Text and client-function messages only (`unsupported_input` for images or audio); the item shape is the relay's (`DurableChatMessage`).",
            "items": {
              "$ref": "#/components/schemas/DurableChatMessage"
            },
            "minItems": 1,
            "type": "array"
          },
          "model": {
            "description": "An exact id returned by `GET /v1/models` for this key.",
            "type": "string"
          },
          "n": {
            "enum": [
              1
            ],
            "type": "integer"
          },
          "parallel_tool_calls": {
            "enum": [
              true
            ],
            "type": "boolean"
          },
          "reasoning_effort": {
            "enum": [
              "none",
              "minimal",
              "low",
              "medium",
              "high",
              "xhigh",
              "max"
            ],
            "type": "string"
          },
          "response_format": {
            "$ref": "#/components/schemas/ResponseFormat"
          },
          "store": {
            "enum": [
              true
            ],
            "type": "boolean"
          },
          "stream": {
            "type": "boolean"
          },
          "stream_options": {
            "additionalProperties": false,
            "description": "Only `{\"include_usage\": true}` is accepted.",
            "properties": {
              "include_usage": {
                "enum": [
                  true
                ],
                "type": "boolean"
              }
            },
            "required": [
              "include_usage"
            ],
            "type": "object"
          },
          "temperature": {
            "type": "number"
          },
          "tool_choice": {
            "description": "`unsupported_tool_choice` for any other value.",
            "enum": [
              "auto",
              "none"
            ],
            "type": "string"
          },
          "tools": {
            "description": "Client function tools only (`unsupported_tools` otherwise); an empty list is refused unless `tool_choice` is `none`.",
            "items": {
              "$ref": "#/components/schemas/Tool"
            },
            "type": "array"
          },
          "user": {
            "type": "string"
          }
        },
        "required": [
          "model",
          "messages"
        ],
        "then": {
          "properties": {
            "tool_choice": {
              "const": "none"
            }
          },
          "required": [
            "tool_choice"
          ]
        },
        "type": "object"
      },
      "DurableChatMessage": {
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "role": {
                  "const": "tool"
                }
              },
              "required": [
                "role"
              ]
            },
            "then": {
              "properties": {
                "content": {
                  "type": "string"
                }
              },
              "required": [
                "tool_call_id",
                "content"
              ]
            }
          },
          {
            "else": {
              "not": {
                "required": [
                  "tool_calls"
                ]
              },
              "properties": {
                "content": {
                  "type": [
                    "string",
                    "array"
                  ]
                }
              },
              "required": [
                "content"
              ]
            },
            "if": {
              "properties": {
                "role": {
                  "const": "assistant"
                }
              },
              "required": [
                "role"
              ]
            },
            "then": {
              "anyOf": [
                {
                  "properties": {
                    "content": {
                      "type": [
                        "string",
                        "array"
                      ]
                    }
                  },
                  "required": [
                    "content"
                  ]
                },
                {
                  "required": [
                    "tool_calls"
                  ]
                }
              ]
            }
          }
        ],
        "description": "A message of the durable chat subset: `role`, `content`, `name`, `tool_call_id`, `tool_calls` and nothing else (`unsupported_input`); text parts are `{type: \"text\", text}` only; a tool result is a string with `tool_call_id`; `content` may be null only on an assistant message with `tool_calls`; `tool_calls` only on an assistant message (`unsupported_tools`).",
        "properties": {
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              },
              {
                "items": {
                  "additionalProperties": false,
                  "properties": {
                    "text": {
                      "type": "string"
                    },
                    "type": {
                      "enum": [
                        "text"
                      ],
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "text"
                  ],
                  "type": "object"
                },
                "type": "array"
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "role": {
            "enum": [
              "system",
              "developer",
              "user",
              "assistant",
              "tool"
            ],
            "type": "string"
          },
          "tool_call_id": {
            "type": "string"
          },
          "tool_calls": {
            "items": {
              "$ref": "#/components/schemas/ToolCall"
            },
            "minItems": 1,
            "type": "array"
          }
        },
        "required": [
          "role"
        ],
        "type": "object"
      },
      "ErrorCode": {
        "description": "Every typed `error.code` this surface answers; the map of code → status and source is in `x-portal-error-codes`. The store also mints `invalid_<field>` (400) for a malformed field of the run contract, and a model-policy refusal answers 403 with a code of the `model_policy_*` family. The model proxy's 401 carries the status as the string code \"401\"; its key-policy 403 carries `key_model_access_denied` as both `error.code` and `error.type`, with the refused id in `error.model`.",
        "enum": [
          "account_inactive",
          "account_suspended",
          "agent_error",
          "agent_looping",
          "audio_transcription_failed",
          "bad_reference",
          "capability_discovery_unavailable",
          "chat_run_cut",
          "conflicting_output_limits",
          "durable_admission_withdrawn",
          "durable_privacy_not_admitted",
          "durable_privacy_unavailable",
          "durable_runs_unavailable",
          "forbidden",
          "future_cursor",
          "host_storage_unqualified",
          "idempotency_conflict",
          "image_admission_unavailable",
          "image_authorization_unavailable",
          "image_identity_required",
          "image_isolation_unavailable",
          "image_not_generated",
          "image_too_large",
          "images_in_flight",
          "included_search_timeout",
          "incomplete_tool_results",
          "insufficient_balance",
          "invalid_api_key",
          "invalid_cursor",
          "invalid_event_limit",
          "invalid_format",
          "invalid_idempotency_key",
          "invalid_input",
          "invalid_json",
          "invalid_json_output",
          "invalid_metadata",
          "invalid_model_policy",
          "invalid_output_limit",
          "invalid_request",
          "invalid_request_digest",
          "invalid_response_format",
          "invalid_run_contract",
          "invalid_run_id",
          "key_model_access_denied",
          "method_not_allowed",
          "model_entitlement_sync_pending",
          "model_not_allowed",
          "model_not_found",
          "model_policy_conflict",
          "model_required",
          "model_variance",
          "no_capacity",
          "no_upstream",
          "output_limit_exceeded",
          "portal_image_limit_reached",
          "portal_web_incomplete",
          "portal_web_timeout",
          "premium_pool_exhausted",
          "process_canary_not_admitted",
          "rate_limit_exceeded",
          "reasoning_limit_exceeded",
          "relay_retiring",
          "request_too_large",
          "response_schema_mismatch",
          "run_authority_required",
          "run_authorization_changed",
          "run_budget_exceeded",
          "run_commit_unknown",
          "run_control_unavailable",
          "run_delivery_reconciliation_pending",
          "run_event_missing",
          "run_event_read_too_large",
          "run_expired",
          "run_format_mismatch",
          "run_id_conflict",
          "run_idle_timeout",
          "run_not_found",
          "run_not_terminal",
          "run_reader_unavailable",
          "run_rejected_before_dispatch",
          "run_request_too_large",
          "run_result_unavailable",
          "run_state_invalid",
          "run_storage_unavailable",
          "stream_not_enabled",
          "stream_required",
          "timeout",
          "unauthorized",
          "unsupported_endpoint",
          "unsupported_input",
          "unsupported_media_type",
          "unsupported_parameter",
          "unsupported_previous_response_id",
          "unsupported_reasoning",
          "unsupported_response_schema",
          "unsupported_store",
          "unsupported_text",
          "unsupported_tool_choice",
          "unsupported_tools",
          "upstream_error",
          "wallet_commit_unknown",
          "wallet_insufficient_credit",
          "wallet_post_commit_sync_failed"
        ],
        "type": "string"
      },
      "ErrorEnvelope": {
        "additionalProperties": true,
        "properties": {
          "error": {
            "additionalProperties": true,
            "properties": {
              "code": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/ErrorCode"
                  },
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "A catalog code, the proxy's string status (\"401\"), or null."
              },
              "floor_tokens": {
                "type": "integer"
              },
              "max_tokens": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              },
              "model": {
                "description": "On `key_model_access_denied`: the model id this key was refused.",
                "type": "string"
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reasoning_chars": {
                "type": "integer"
              },
              "reasoning_tokens": {
                "type": "integer"
              },
              "retry_after": {
                "description": "Seconds; equals the `Retry-After` header.",
                "type": "integer"
              },
              "type": {
                "description": "`invalid_request_error`, `authentication_error`, `auth_error` (the proxy's 401), `permission_error`, `rate_limit_error`, `server_error`, `service_unavailable_error`, `upstream_error`, `timeout_error`, `upstream_run_cut`, `run_error`, `key_model_access_denied` (the proxy's key policy).",
                "type": "string"
              },
              "usage": {
                "additionalProperties": true,
                "description": "On a validation refusal: the rejected generation's token counts; never content.",
                "type": "object"
              },
              "visible_tokens": {
                "type": "integer"
              }
            },
            "required": [
              "message"
            ],
            "type": "object"
          },
          "retryable": {
            "description": "Beside `error`, not inside it: set by the key-models, capabilities and images authorizers (`model_entitlement_sync_pending`, `capability_discovery_unavailable`, `image_authorization_unavailable` are true). Absent on the gateway's and the relay's envelopes.",
            "type": "boolean"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      },
      "ImageEditRequest": {
        "additionalProperties": true,
        "anyOf": [
          {
            "required": [
              "image"
            ]
          },
          {
            "required": [
              "images"
            ]
          }
        ],
        "properties": {
          "aspect_ratio": {
            "enum": [
              "1:1",
              "4:3",
              "3:4",
              "16:9",
              "9:16"
            ],
            "type": "string"
          },
          "image": {
            "description": "One reference picture as a data URL or base64 (the request body is capped at 16 MiB; a reference above the worker's byte cap answers 413 `bad_reference`).",
            "maxLength": 16777216,
            "type": "string"
          },
          "images": {
            "description": "Up to three reference pictures; send `image` or `images`.",
            "items": {
              "maxLength": 16777216,
              "type": "string"
            },
            "maxItems": 3,
            "type": "array"
          },
          "n": {
            "enum": [
              1
            ],
            "type": "integer"
          },
          "prompt": {
            "type": "string"
          },
          "response_format": {
            "enum": [
              "b64_json"
            ],
            "type": "string"
          },
          "size": {
            "type": "string"
          }
        },
        "required": [
          "prompt"
        ],
        "type": "object"
      },
      "ImageGenerationRequest": {
        "additionalProperties": true,
        "properties": {
          "aspect_ratio": {
            "enum": [
              "1:1",
              "4:3",
              "3:4",
              "16:9",
              "9:16"
            ],
            "type": "string"
          },
          "n": {
            "enum": [
              1
            ],
            "type": "integer"
          },
          "prompt": {
            "type": "string"
          },
          "response_format": {
            "enum": [
              "b64_json"
            ],
            "type": "string"
          },
          "size": {
            "type": "string"
          }
        },
        "required": [
          "prompt"
        ],
        "type": "object"
      },
      "ImagesResponse": {
        "additionalProperties": true,
        "properties": {
          "created": {
            "type": "integer"
          },
          "data": {
            "items": {
              "additionalProperties": true,
              "properties": {
                "b64_json": {
                  "type": "string"
                },
                "revised_prompt": {
                  "type": "string"
                }
              },
              "type": "object"
            },
            "type": "array"
          }
        },
        "required": [
          "created",
          "data"
        ],
        "type": "object"
      },
      "Model": {
        "additionalProperties": true,
        "properties": {
          "context_window": {
            "type": "integer"
          },
          "created": {
            "type": "integer"
          },
          "effort": {
            "type": "string"
          },
          "effort_source": {
            "type": "string"
          },
          "entitlement": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "object": {
            "enum": [
              "model"
            ],
            "type": "string"
          },
          "owned_by": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "object",
          "owned_by"
        ],
        "type": "object"
      },
      "ModelList": {
        "properties": {
          "data": {
            "items": {
              "$ref": "#/components/schemas/Model"
            },
            "type": "array"
          },
          "object": {
            "enum": [
              "list"
            ],
            "type": "string"
          }
        },
        "required": [
          "object",
          "data"
        ],
        "type": "object"
      },
      "Response": {
        "additionalProperties": true,
        "properties": {
          "background": {
            "type": "boolean"
          },
          "created_at": {
            "type": "integer"
          },
          "error": {
            "additionalProperties": true,
            "type": [
              "object",
              "null"
            ]
          },
          "id": {
            "pattern": "^resp_[a-f0-9]{40}$",
            "type": "string"
          },
          "incomplete_details": {
            "additionalProperties": true,
            "type": [
              "object",
              "null"
            ]
          },
          "instructions": {
            "type": [
              "string",
              "null"
            ]
          },
          "metadata": {
            "additionalProperties": {
              "type": "string"
            },
            "type": "object"
          },
          "model": {
            "type": "string"
          },
          "object": {
            "enum": [
              "response"
            ],
            "type": "string"
          },
          "output": {
            "items": {
              "additionalProperties": true,
              "description": "`message` items with `output_text` parts, `reasoning` items, `function_call` items.",
              "type": "object"
            },
            "type": "array"
          },
          "parallel_tool_calls": {
            "type": "boolean"
          },
          "portal_usage": {
            "additionalProperties": true,
            "type": [
              "object",
              "null"
            ]
          },
          "previous_response_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "reasoning": {
            "additionalProperties": true,
            "type": [
              "object",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/ResponseStatusValue"
          },
          "store": {
            "type": "boolean"
          },
          "temperature": {
            "type": [
              "number",
              "null"
            ]
          },
          "text": {
            "additionalProperties": true,
            "type": "object"
          },
          "tool_choice": {
            "type": "string"
          },
          "tools": {
            "items": {
              "additionalProperties": true,
              "type": "object"
            },
            "type": "array"
          },
          "top_p": {
            "type": [
              "number",
              "null"
            ]
          },
          "truncation": {
            "type": "string"
          },
          "usage": {
            "additionalProperties": true,
            "type": [
              "object",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "object",
          "created_at",
          "status",
          "model"
        ],
        "type": "object"
      },
      "ResponseCreateRequest": {
        "additionalProperties": false,
        "properties": {
          "background": {
            "description": "`true` for a durable run; `stream: true` beside it when streamed retrieval is wanted.",
            "type": "boolean"
          },
          "input": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "items": {
                  "$ref": "#/components/schemas/ResponseInputItem"
                },
                "minItems": 1,
                "type": "array"
              }
            ]
          },
          "instructions": {
            "type": "string"
          },
          "metadata": {
            "additionalProperties": {
              "maxLength": 512,
              "type": "string"
            },
            "description": "Up to sixteen string values; keys of at most 64 characters, values of at most 512 (`invalid_metadata`).",
            "maxProperties": 16,
            "propertyNames": {
              "maxLength": 64
            },
            "type": "object"
          },
          "model": {
            "type": "string"
          },
          "parallel_tool_calls": {
            "enum": [
              true
            ],
            "type": "boolean"
          },
          "reasoning": {
            "additionalProperties": false,
            "properties": {
              "effort": {
                "enum": [
                  "none",
                  "minimal",
                  "low",
                  "medium",
                  "high",
                  "xhigh",
                  "max"
                ],
                "type": "string"
              }
            },
            "required": [
              "effort"
            ],
            "type": "object"
          },
          "store": {
            "description": "`false` is refused on this subset (`unsupported_store`).",
            "enum": [
              true
            ],
            "type": "boolean"
          },
          "stream": {
            "type": "boolean"
          },
          "text": {
            "properties": {
              "format": {
                "oneOf": [
                  {
                    "properties": {
                      "type": {
                        "enum": [
                          "text",
                          "json_object"
                        ],
                        "type": "string"
                      }
                    },
                    "required": [
                      "type"
                    ],
                    "type": "object"
                  },
                  {
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "schema": {
                        "additionalProperties": true,
                        "type": "object"
                      },
                      "strict": {
                        "type": "boolean"
                      },
                      "type": {
                        "enum": [
                          "json_schema"
                        ],
                        "type": "string"
                      }
                    },
                    "required": [
                      "type",
                      "name",
                      "schema"
                    ],
                    "type": "object"
                  }
                ]
              }
            },
            "required": [
              "format"
            ],
            "type": "object"
          },
          "tool_choice": {
            "enum": [
              "auto",
              "none"
            ],
            "type": "string"
          },
          "tools": {
            "items": {
              "properties": {
                "description": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "parameters": {
                  "additionalProperties": true,
                  "type": "object"
                },
                "type": {
                  "enum": [
                    "function"
                  ],
                  "type": "string"
                }
              },
              "required": [
                "type",
                "name"
              ],
              "type": "object"
            },
            "type": "array"
          }
        },
        "required": [
          "model",
          "input"
        ],
        "type": "object"
      },
      "ResponseFormat": {
        "oneOf": [
          {
            "properties": {
              "type": {
                "enum": [
                  "text",
                  "json_object"
                ],
                "type": "string"
              }
            },
            "required": [
              "type"
            ],
            "type": "object"
          },
          {
            "properties": {
              "json_schema": {
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "schema": {
                    "additionalProperties": true,
                    "description": "An object-root Draft-07 schema within size and depth limits; list every field under `required` and give each a `type` or an `enum` (`required` alone accepts null).",
                    "type": "object"
                  },
                  "strict": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name",
                  "schema"
                ],
                "type": "object"
              },
              "type": {
                "enum": [
                  "json_schema"
                ],
                "type": "string"
              }
            },
            "required": [
              "type",
              "json_schema"
            ],
            "type": "object"
          }
        ]
      },
      "ResponseInputItem": {
        "oneOf": [
          {
            "properties": {
              "content": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "items": {
                      "properties": {
                        "text": {
                          "type": "string"
                        },
                        "type": {
                          "enum": [
                            "input_text",
                            "output_text"
                          ],
                          "type": "string"
                        }
                      },
                      "required": [
                        "type",
                        "text"
                      ],
                      "type": "object"
                    },
                    "type": "array"
                  }
                ]
              },
              "role": {
                "enum": [
                  "system",
                  "developer",
                  "user",
                  "assistant"
                ],
                "type": "string"
              },
              "type": {
                "enum": [
                  "message"
                ],
                "type": "string"
              }
            },
            "required": [
              "role",
              "content"
            ],
            "type": "object"
          },
          {
            "properties": {
              "arguments": {
                "type": "string"
              },
              "call_id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "type": {
                "enum": [
                  "function_call"
                ],
                "type": "string"
              }
            },
            "required": [
              "type",
              "call_id",
              "name",
              "arguments"
            ],
            "type": "object"
          },
          {
            "properties": {
              "call_id": {
                "type": "string"
              },
              "output": {
                "type": "string"
              },
              "type": {
                "enum": [
                  "function_call_output"
                ],
                "type": "string"
              }
            },
            "required": [
              "type",
              "call_id",
              "output"
            ],
            "type": "object"
          }
        ]
      },
      "ResponseStatus": {
        "properties": {
          "background": {
            "type": "boolean"
          },
          "created_at": {
            "type": "integer"
          },
          "id": {
            "pattern": "^resp_[a-f0-9]{40}$",
            "type": "string"
          },
          "last_sequence_number": {
            "description": "The highest committed cursor; -1 before the first event.",
            "minimum": -1,
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "object": {
            "enum": [
              "response.status"
            ],
            "type": "string"
          },
          "retention": {
            "properties": {
              "expires_at": {
                "format": "date-time",
                "type": [
                  "string",
                  "null"
                ]
              },
              "terminal_seconds": {
                "type": "integer"
              }
            },
            "type": "object"
          },
          "status": {
            "$ref": "#/components/schemas/ResponseStatusValue"
          }
        },
        "required": [
          "id",
          "object",
          "status",
          "created_at"
        ],
        "type": "object"
      },
      "ResponseStatusValue": {
        "description": "The public image of the stored run state (run-wire.mjs publicStatus): `queued` and `in_progress` are the only non-terminal states.",
        "enum": [
          "queued",
          "in_progress",
          "completed",
          "failed",
          "cancelled"
        ],
        "type": "string"
      },
      "ResponseStreamEvent": {
        "additionalProperties": true,
        "properties": {
          "sequence_number": {
            "description": "The exclusive resume cursor; also the frame's `id:` line.",
            "minimum": 0,
            "type": "integer"
          },
          "type": {
            "description": "`response.created`, `response.in_progress`, `response.output_item.added`, `response.content_part.added`, `response.output_text.delta`, `response.reasoning_text.delta`, `response.function_call_arguments.delta` / `.done`, `response.output_text.done`, `response.content_part.done`, `response.output_item.done`, `response.completed`, `response.failed`, `error`, `portal.delivery_error`.",
            "type": "string"
          }
        },
        "required": [
          "type",
          "sequence_number"
        ],
        "type": "object"
      },
      "Tool": {
        "properties": {
          "function": {
            "properties": {
              "description": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "parameters": {
                "additionalProperties": true,
                "type": "object"
              }
            },
            "required": [
              "name"
            ],
            "type": "object"
          },
          "type": {
            "enum": [
              "function"
            ],
            "type": "string"
          }
        },
        "required": [
          "type",
          "function"
        ],
        "type": "object"
      },
      "ToolCall": {
        "properties": {
          "function": {
            "properties": {
              "arguments": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "arguments"
            ],
            "type": "object"
          },
          "id": {
            "type": "string"
          },
          "type": {
            "enum": [
              "function"
            ],
            "type": "string"
          }
        },
        "required": [
          "id",
          "type",
          "function"
        ],
        "type": "object"
      },
      "Usage": {
        "additionalProperties": true,
        "properties": {
          "completion_tokens": {
            "type": "integer"
          },
          "portal_output_tokens": {
            "additionalProperties": true,
            "properties": {
              "reasoning_tokens": {
                "type": "integer"
              },
              "tokenizer": {
                "type": "string"
              },
              "visible_tokens": {
                "type": "integer"
              }
            },
            "type": "object"
          },
          "prompt_tokens": {
            "type": "integer"
          },
          "prompt_tokens_details": {
            "properties": {
              "cached_tokens": {
                "type": "integer"
              }
            },
            "type": "object"
          },
          "total_tokens": {
            "type": "integer"
          }
        },
        "type": "object"
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "bearerFormat": "sk-portal-… (created in the dashboard's API Keys tab; shown once)",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "contact": {
      "email": "support@portal.ai",
      "name": "Portal support",
      "url": "https://platform.portal.ai/docs.html"
    },
    "description": "Point any OpenAI-compatible client at `https://api.portal.ai/v1` with a `sk-portal-…` key. Chat completions, streaming, tool calling, structured output, model discovery, images, and durable (background) runs that survive a dropped connection and resume from a cursor. Human documentation: https://platform.portal.ai/docs.html. This document is generated from the gateway's own route constants, the public vhost and the typed error literals of its sources (platform/tools/openapi-generate.mjs) and served at https://api.portal.ai/openapi.json.",
    "summary": "Frontier models through one OpenAI-compatible API, metered in USD.",
    "termsOfService": "https://platform.portal.ai/legal/terms",
    "title": "Portal Platform API",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/openapi.json": {
      "get": {
        "operationId": "getOpenApiDocument",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "type": "object"
                }
              }
            },
            "description": "The OpenAPI 3.1 description of this surface (no key needed)."
          }
        },
        "security": [],
        "summary": "This document",
        "tags": [
          "meta"
        ]
      }
    },
    "/v1/capabilities": {
      "get": {
        "operationId": "getCapabilities",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Capabilities"
                }
              }
            },
            "description": "The capability descriptor."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A refused key answers the JSON envelope: 401 `unauthorized` (missing, invalid or revoked key)."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`account_suspended`; a model-policy refusal — `model_policy_conflict` (the default) or `invalid_model_policy` and the other `ModelPolicyError` codes of platform/api/model-aliases.mjs; `account_inactive`: the account is not active; `forbidden` when the auth subrequest refuses the key."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`model_entitlement_sync_pending` (the entitlement is still synchronizing) or `capability_discovery_unavailable` (the live capability inventory could not be read; no model was called) — both with a top-level `retryable: true` and no `Retry-After` header."
          }
        },
        "summary": "Read-only capability descriptor for this key",
        "tags": [
          "models"
        ]
      }
    },
    "/v1/chat/completions": {
      "post": {
        "description": "OpenAI-compatible chat completion. Streaming with `stream: true` keeps the socket open and does not shorten thinking. A buffered call on a long-reasoning route is allowed 3600 s; the public edge waits 3720 s, so set a client timeout above 3780 s to wait for the full allowance (https://platform.portal.ai/docs.html#long-requests). With `X-Portal-Durable: 1` and an `Idempotency-Key` on an admitted account the same request becomes a durable run — its body must then satisfy `DurableChatCompletionRequest` (the relay's allowlist; an unknown field answers 400 `unsupported_parameter`) — that keeps its chat chunk format and `[DONE]` and resumes through `GET /v1/responses/{response_id}?stream=true&format=chat.completions&starting_after=N`. Durable (background) runs are admitted per account; a request outside the admitted set answers 403 `process_canary_not_admitted`. Every durable creation requires an `Idempotency-Key`; the reply carries `X-Portal-Run-Id` and `X-Portal-Run-Retention`, and `X-Portal-Run-Storage-Profile` names the failure scope (`process` = survives reader, relay and executor loss; not the host). See https://platform.portal.ai/docs.html#resume-stream.",
        "operationId": "createChatCompletion",
        "parameters": [
          {
            "$ref": "#/components/parameters/XPortalDurable"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/XPortalTool"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/ChatCompletionRequest"
                  },
                  {
                    "$ref": "#/components/schemas/DurableChatCompletionRequest"
                  }
                ],
                "description": "The native shape, or — with `X-Portal-Durable: 1` — the durable subset."
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionChunk",
                  "description": "Server-sent events (`text/event-stream`): each frame carries `id: <sequence_number>` (the exclusive resume cursor), `data: <ChatCompletionChunk JSON>` and the final `data: [DONE]`, and a blank line; comment lines (`: keepalive`) are not events and carry no cursor. A stream that ends without its terminal frame did not finish."
                }
              }
            },
            "description": "The completion, or the stream of chunks when `stream: true`.",
            "headers": {
              "X-Portal-Run-Id": {
                "$ref": "#/components/headers/XPortalRunId"
              },
              "X-Portal-Run-Retention": {
                "$ref": "#/components/headers/XPortalRunRetention"
              },
              "X-Portal-Run-Storage-Profile": {
                "$ref": "#/components/headers/XPortalRunStorageProfile"
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Malformed request; `output_limit_exceeded` (its body names `floor_tokens` and `max_tokens`) / `reasoning_limit_exceeded` for the validated-output contract; `stream_required` when a buffered body asks for more than the route's allowance; `model_not_found`: the requested model is not available on this endpoint (final — retrying does not help); on the durable opt-in `unsupported_parameter`, `invalid_idempotency_key` and the relay's other 400 codes."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "The model proxy's own answer to a missing, invalid or revoked key: `error.type` `auth_error` or `token_not_found_in_db`, `error.code` the string \"401\" (the status, not a catalog code), `error.param` `key`."
          },
          "402": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`wallet_insufficient_credit`: the durable opt-in could not reserve the run's quoted amount."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`key_model_access_denied` (the proxy's key policy: this key's model menu does not include the requested model; `error.code` and `error.type` both say it, `error.model` names the refused id and the message lists the ids this key can call; not retryable — it is not an outage); `process_canary_not_admitted`: the durable opt-in on an account not admitted to the canary."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A durable creation route answers only POST."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`idempotency_conflict`: the Idempotency-Key names a different request; `run_id_conflict`: the derived run id already exists; `durable_privacy_unavailable`: a protected identity needs the memory-only route."
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "The request body is larger than 16 MiB (`run_request_too_large` on the durable opt-in)."
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`rate_limit_exceeded` with `Retry-After`: briefly at full capacity (ours, or the model vendor's since 2026-11-01); safe to retry, not billed. A `Budget has been exceeded` 429 without `Retry-After` is an empty wallet or key cap; retrying does not help. `premium_pool_exhausted` with `Retry-After`: every premium seat for this model family is at its usage limit; retry after the reset or pick another family (not billed).",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A transient server error, or `model_variance` when a stream ended below the reasoning ceiling without a complete JSON object (not billed)."
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`upstream_error`: the model provider failed to complete the request; `chat_run_cut`: the model reached for a tool this chat does not have; `response_schema_mismatch`: the validated output did not match the schema; `portal_web_incomplete` / `included_search_timeout`: the web-assisted answer did not finish; `run_budget_exceeded`: the run spent its turn or output-token budget without a final answer (not billed); `agent_looping`: the upstream stopped the run because the model was looping (not billed)."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`no_upstream`: no model server is available at the edge; `no_capacity`: no key with room; `durable_runs_unavailable` / `relay_retiring` / `durable_admission_withdrawn` on the durable opt-in.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "504": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_idle_timeout`: the model request reached its progress timeout; `portal_web_timeout`: the web-assisted answer timed out."
          }
        },
        "summary": "Create a chat completion",
        "tags": [
          "chat"
        ]
      }
    },
    "/v1/images/edits": {
      "post": {
        "operationId": "createImageEdit",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageEditRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImagesResponse"
                }
              }
            },
            "description": "One edited image."
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`invalid_json`, `invalid_request` (`prompt`, `n`, `aspect_ratio`, `response_format`, `image`), `bad_reference` (a reference that is not a data URL or base64 picture)."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A refused key answers the JSON envelope: 401 `unauthorized` (missing, invalid or revoked key)."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Image access denied for this key or account: `model_not_allowed`, `account_suspended` or `insufficient_balance` (the authorizer; the same code rides `X-Portal-Images-Error`), or `image_identity_required` (the worker's image store does not know this key).",
            "headers": {
              "X-Portal-Images-Error": {
                "$ref": "#/components/headers/XPortalImagesError"
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`unsupported_endpoint`: image generation is disabled on this gateway."
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_too_large`: the picture exceeds the worker's byte cap; `bad_reference`: a reference image exceeds it."
          },
          "415": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`unsupported_media_type`: send `application/json` (a data URL or base64 in `image`; multipart is not accepted)."
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`images_in_flight`: too many pictures in flight on this worker; `no_capacity`: no account with room in the pool (both carry `Retry-After`); `portal_image_limit_reached`: this key's image quota (per minute or per day) is spent — no `Retry-After`.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_not_generated` / `agent_error`: the image worker did not return a picture."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_authorization_unavailable` with `Retry-After: 5` and a top-level `retryable: true`: the edge's own page for an images auth subrequest that answered neither 2xx nor 401/403 — the authorizer's 503 (it could not reach the model proxy) and also a 500 or 502 from that subrequest (nginx folds them into one page; the worker's own 500 after a successful authorization is passed through unchanged); `image_isolation_unavailable`, `image_admission_unavailable` from the worker.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "504": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`timeout`: no picture within the worker's time budget."
          }
        },
        "summary": "Edit an image with reference images",
        "tags": [
          "images"
        ]
      }
    },
    "/v1/images/generations": {
      "post": {
        "description": "The OpenAI Images shape, JSON only, `n: 1`, `response_format: b64_json`; a separately metered route — model-only keys may be denied.",
        "operationId": "createImage",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ImageGenerationRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImagesResponse"
                }
              }
            },
            "description": "One generated image."
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`invalid_json`, `invalid_request` (`prompt`, `n`, `aspect_ratio`, `response_format`, `image`), `bad_reference` (a reference that is not a data URL or base64 picture)."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A refused key answers the JSON envelope: 401 `unauthorized` (missing, invalid or revoked key)."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Image access denied for this key or account: `model_not_allowed`, `account_suspended` or `insufficient_balance` (the authorizer; the same code rides `X-Portal-Images-Error`), or `image_identity_required` (the worker's image store does not know this key).",
            "headers": {
              "X-Portal-Images-Error": {
                "$ref": "#/components/headers/XPortalImagesError"
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`unsupported_endpoint`: image generation is disabled on this gateway."
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_too_large`: the picture exceeds the worker's byte cap; `bad_reference`: a reference image exceeds it."
          },
          "415": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`unsupported_media_type`: send `application/json` (a data URL or base64 in `image`; multipart is not accepted)."
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`images_in_flight`: too many pictures in flight on this worker; `no_capacity`: no account with room in the pool (both carry `Retry-After`); `portal_image_limit_reached`: this key's image quota (per minute or per day) is spent — no `Retry-After`.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_not_generated` / `agent_error`: the image worker did not return a picture."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`image_authorization_unavailable` with `Retry-After: 5` and a top-level `retryable: true`: the edge's own page for an images auth subrequest that answered neither 2xx nor 401/403 — the authorizer's 503 (it could not reach the model proxy) and also a 500 or 502 from that subrequest (nginx folds them into one page; the worker's own 500 after a successful authorization is passed through unchanged); `image_isolation_unavailable`, `image_admission_unavailable` from the worker.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "504": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`timeout`: no picture within the worker's time budget."
          }
        },
        "summary": "Generate an image",
        "tags": [
          "images"
        ]
      }
    },
    "/v1/models": {
      "get": {
        "description": "OpenAI's list format, rendered from the key's stored entitlement: the exact ids to pass as `model`, with `context_window`, `effort` and `entitlement` when known. A public catalog id may not be enabled for a key; a restricted key can carry only private ids. A refused key answers the JSON envelope: 401 `unauthorized` (missing, invalid or revoked key).",
        "operationId": "listModels",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            },
            "description": "The key's model list."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "A refused key answers the JSON envelope: 401 `unauthorized` (missing, invalid or revoked key)."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`account_suspended`; a model-policy refusal — `model_policy_conflict` (the default) or `invalid_model_policy` and the other `ModelPolicyError` codes of platform/api/model-aliases.mjs; `forbidden` when the auth subrequest refuses the key."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`model_entitlement_sync_pending` with a top-level `retryable: true` beside the `error` object and no `Retry-After` header: a newly granted entitlement is still synchronizing to this key — retry after its model policy has synchronized (the reconciler runs hourly)."
          }
        },
        "summary": "List the models this key can call",
        "tags": [
          "models"
        ]
      }
    },
    "/v1/responses": {
      "post": {
        "description": "The Responses subset: text and client-function input, `background: true` and optional `stream: true` (the JSON body's `stream` is the switch; there is no query switch on creation); `store: false` and `previous_response_id` are refused. The `Idempotency-Key` header is required and is checked before the body is read. A background run finishing by itself does not incur the delivery charge; complete delivery, including parts collected across reconnects, is charged once; a replay of a paid result adds no charge. Durable (background) runs are admitted per account; a request outside the admitted set answers 403 `process_canary_not_admitted`. Every durable creation requires an `Idempotency-Key`; the reply carries `X-Portal-Run-Id` and `X-Portal-Run-Retention`, and `X-Portal-Run-Storage-Profile` names the failure scope (`process` = survives reader, relay and executor loss; not the host). See https://platform.portal.ai/docs.html#resume-stream.",
        "operationId": "createResponse",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyRequired"
          },
          {
            "$ref": "#/components/parameters/starting_after"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResponseCreateRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              },
              "text/event-stream": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseStreamEvent",
                  "description": "Server-sent events (`text/event-stream`): each frame carries `id: <sequence_number>` (the exclusive resume cursor), `event: <type>` and `data: <event JSON with type and sequence_number>`; the stream finishes with `response.completed` or `response.failed`, and a blank line; comment lines (`: keepalive`) are not events and carry no cursor. A stream that ends without its terminal frame did not finish."
                }
              }
            },
            "description": "The queued response object (`background: true` without `stream`), the completed result, or the event stream.",
            "headers": {
              "X-Portal-Run-Id": {
                "$ref": "#/components/headers/XPortalRunId"
              },
              "X-Portal-Run-Retention": {
                "$ref": "#/components/headers/XPortalRunRetention"
              },
              "X-Portal-Run-Storage-Profile": {
                "$ref": "#/components/headers/XPortalRunStorageProfile"
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`invalid_idempotency_key` (the header is required), `invalid_request`, `unsupported_*` (a parameter outside the subset), `invalid_cursor` / `future_cursor`."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing, invalid or revoked API key."
          },
          "402": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`wallet_insufficient_credit`: the run's quoted amount could not be reserved."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`process_canary_not_admitted`: this account is not admitted to the durable canary."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`method_not_allowed`: use POST."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`idempotency_conflict`: the key names a different request; `durable_privacy_unavailable`; `run_id_conflict`."
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`request_too_large` (16 MiB) / `run_request_too_large`."
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`rate_limit_exceeded` with `Retry-After`.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`durable_runs_unavailable`, `relay_retiring` (retry admission with the same key), `durable_admission_withdrawn`, `run_storage_unavailable`, `run_unavailable`.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          }
        },
        "summary": "Create a durable response (background run)",
        "tags": [
          "responses"
        ]
      }
    },
    "/v1/responses/{response_id}": {
      "get": {
        "description": "Without `stream=true`: the unfinished status object, or the completed result (billable delivery, the final polling GET included). With `stream=true`: exclusive replay from the cursor and the live tail; a chat-format run adds `format=chat.completions`. Both cursors (`starting_after` and `Last-Event-ID`) are validated: an invalid value answers 400 `invalid_cursor` even beside a valid one, and when both are valid the greater sequence wins. An authorized expired run answers 410; an absent or cross-tenant id answers 404.",
        "operationId": "getResponse",
        "parameters": [
          {
            "description": "The run id from `X-Portal-Run-Id`.",
            "in": "path",
            "name": "response_id",
            "required": true,
            "schema": {
              "pattern": "^resp_[a-f0-9]{40}$",
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/stream"
          },
          {
            "$ref": "#/components/parameters/starting_after"
          },
          {
            "$ref": "#/components/parameters/format"
          },
          {
            "$ref": "#/components/parameters/LastEventID"
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              },
              "text/event-stream": {
                "schema": {
                  "description": "Server-sent events (`text/event-stream`): each frame carries `id: <sequence_number>` (the exclusive resume cursor), the run's original wire format (`format` must match it), and a blank line; comment lines (`: keepalive`) are not events and carry no cursor. A stream that ends without its terminal frame did not finish.",
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ResponseStreamEvent"
                    },
                    {
                      "$ref": "#/components/schemas/ChatCompletionChunk"
                    }
                  ]
                }
              }
            },
            "description": "The response object or the resumed stream.",
            "headers": {
              "X-Portal-Run-Id": {
                "$ref": "#/components/headers/XPortalRunId"
              },
              "X-Portal-Run-Retention": {
                "$ref": "#/components/headers/XPortalRunRetention"
              },
              "X-Portal-Run-Storage-Profile": {
                "$ref": "#/components/headers/XPortalRunStorageProfile"
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`invalid_cursor`, `future_cursor`, `run_format_mismatch`, `stream_not_enabled`."
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_not_found`: absent, another account's, or an unauthorized key."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`method_not_allowed`: use GET."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_rejected_before_dispatch`: the run was refused before generation under its current policy."
          },
          "410": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_expired`: the retained run reached its expiry."
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_event_read_too_large`: one committed event is larger than the read window."
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_result_unavailable`, `run_delivery_reconciliation_pending`, `run_reader_unavailable`, `relay_retiring`.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            }
          }
        },
        "summary": "Retrieve a response, or resume its stream",
        "tags": [
          "responses"
        ]
      }
    },
    "/v1/responses/{response_id}/cancel": {
      "post": {
        "description": "Cancellation is an intent recorded under the current owner's lease; the execution owner acknowledges the terminal outcome. Closing a background stream does not cancel; this does.",
        "operationId": "cancelResponse",
        "parameters": [
          {
            "description": "The run id from `X-Portal-Run-Id`.",
            "in": "path",
            "name": "response_id",
            "required": true,
            "schema": {
              "pattern": "^resp_[a-f0-9]{40}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              }
            },
            "description": "The response object with its current status.",
            "headers": {
              "X-Portal-Run-Id": {
                "$ref": "#/components/headers/XPortalRunId"
              },
              "X-Portal-Run-Retention": {
                "$ref": "#/components/headers/XPortalRunRetention"
              },
              "X-Portal-Run-Storage-Profile": {
                "$ref": "#/components/headers/XPortalRunStorageProfile"
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_not_found`: absent, another account's, or an unauthorized key."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`method_not_allowed`: use POST."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_rejected_before_dispatch`: the run was refused before generation under its current policy."
          },
          "410": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_expired`: the retained run reached its expiry."
          }
        },
        "summary": "Cancel a run (idempotent)",
        "tags": [
          "responses"
        ]
      }
    },
    "/v1/responses/{response_id}/status": {
      "get": {
        "operationId": "getResponseStatus",
        "parameters": [
          {
            "description": "The run id from `X-Portal-Run-Id`.",
            "in": "path",
            "name": "response_id",
            "required": true,
            "schema": {
              "pattern": "^resp_[a-f0-9]{40}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseStatus"
                }
              }
            },
            "description": "The public status, the cursor and the retention; no artifact.",
            "headers": {
              "X-Portal-Run-Id": {
                "$ref": "#/components/headers/XPortalRunId"
              },
              "X-Portal-Run-Retention": {
                "$ref": "#/components/headers/XPortalRunRetention"
              },
              "X-Portal-Run-Storage-Profile": {
                "$ref": "#/components/headers/XPortalRunStorageProfile"
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_not_found`: absent, another account's, or an unauthorized key."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`method_not_allowed`: use GET."
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_rejected_before_dispatch`: the run was refused before generation under its current policy."
          },
          "410": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "`run_expired`: the retained run reached its expiry."
          }
        },
        "summary": "Status and cursor without output",
        "tags": [
          "responses"
        ]
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "servers": [
    {
      "description": "Paths are absolute here; OpenAI SDKs take the base URL with the `/v1` prefix.",
      "url": "https://api.portal.ai"
    }
  ],
  "tags": [
    {
      "name": "chat"
    },
    {
      "description": "Durable background runs: create, poll, resume, cancel.",
      "name": "responses"
    },
    {
      "name": "models"
    },
    {
      "name": "images"
    },
    {
      "name": "meta"
    }
  ],
  "x-portal-error-codes": {
    "account_inactive": {
      "source": "platform/api/server.mjs keyModelsForApi",
      "statuses": [
        403
      ]
    },
    "account_suspended": {
      "source": "platform/api/images-authorize.mjs · platform/api/server.mjs keyModelsForApi",
      "statuses": [
        403
      ]
    },
    "agent_error": {
      "source": "portal-gateway/image-gen.mjs",
      "statuses": [
        500,
        502
      ]
    },
    "agent_looping": {
      "source": "platform/litellm/typed_errors.py GATEWAY_TYPED_CODES (the upstream's in-stream loop stop; relayed unchanged, not billed)",
      "statuses": [
        502
      ]
    },
    "audio_transcription_failed": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        502
      ]
    },
    "bad_reference": {
      "source": "portal-gateway/image-gen.mjs",
      "statuses": [
        400,
        413
      ]
    },
    "capability_discovery_unavailable": {
      "source": "platform/api/server.mjs keyModelsForApi",
      "statuses": [
        503
      ]
    },
    "chat_run_cut": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        502
      ]
    },
    "conflicting_output_limits": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        400
      ]
    },
    "durable_admission_withdrawn": {
      "source": "platform/tools/durable_deploy.py",
      "statuses": [
        503
      ]
    },
    "durable_privacy_not_admitted": {
      "source": "platform/api/durable-runtime.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        403
      ]
    },
    "durable_privacy_unavailable": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        409
      ]
    },
    "durable_runs_unavailable": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        503
      ]
    },
    "forbidden": {
      "source": "platform/nginx/api.portal.ai.conf",
      "statuses": [
        403
      ]
    },
    "future_cursor": {
      "source": "portal-gateway/run-wire.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "host_storage_unqualified": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        503
      ]
    },
    "idempotency_conflict": {
      "source": "platform/api/durable-runs.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        409
      ]
    },
    "image_admission_unavailable": {
      "source": "portal-gateway/server.mjs handleImages · portal-gateway/web-tools-store.mjs reserveImageOperation",
      "statuses": [
        503
      ]
    },
    "image_authorization_unavailable": {
      "source": "platform/api/images-authorize.mjs · platform/nginx/api.portal.ai.conf",
      "statuses": [
        503
      ]
    },
    "image_identity_required": {
      "source": "portal-gateway/web-tools-store.mjs reserveImageOperation",
      "statuses": [
        403
      ]
    },
    "image_isolation_unavailable": {
      "source": "portal-gateway/server.mjs handleImages",
      "statuses": [
        503
      ]
    },
    "image_not_generated": {
      "source": "portal-gateway/image-gen.mjs",
      "statuses": [
        502
      ]
    },
    "image_too_large": {
      "source": "portal-gateway/image-gen.mjs (`new ImageGenError(err.code, err.message, 413)` when the worker reports image_too_large)",
      "statuses": [
        413
      ]
    },
    "images_in_flight": {
      "source": "portal-gateway/server.mjs handleImages",
      "statuses": [
        429
      ]
    },
    "included_search_timeout": {
      "source": "portal-gateway/native-web.mjs (`portalWebError`), mapped by httpErrorFor",
      "statuses": [
        502
      ]
    },
    "incomplete_tool_results": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        400
      ]
    },
    "insufficient_balance": {
      "source": "platform/api/images-authorize.mjs",
      "statuses": [
        403
      ]
    },
    "invalid_api_key": {
      "source": "platform/api/durable-control-client.mjs",
      "statuses": [
        401
      ]
    },
    "invalid_cursor": {
      "source": "platform/api/durable-runtime.mjs · portal-gateway/run-wire.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "invalid_event_limit": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "invalid_format": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_idempotency_key": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_input": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_json": {
      "source": "platform/api/durable-runs.mjs · portal-gateway/image-gen.mjs · portal-gateway/server.mjs handleImages",
      "statuses": [
        400
      ]
    },
    "invalid_json_output": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        502
      ]
    },
    "invalid_metadata": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_model_policy": {
      "source": "platform/api/model-aliases.mjs",
      "statuses": [
        403
      ]
    },
    "invalid_output_limit": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_request": {
      "source": "portal-gateway/run-wire.mjs · portal-gateway/image-gen.mjs · portal-gateway/openai-response.mjs httpErrorFor · portal-gateway/server.mjs handleImages (`e.code || \"invalid_request\"` from parseImageRequest)",
      "statuses": [
        400
      ]
    },
    "invalid_request_digest": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "invalid_response_format": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        400
      ]
    },
    "invalid_run_contract": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "invalid_run_id": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "key_model_access_denied": {
      "source": "platform/litellm/key_access.py",
      "statuses": [
        403
      ]
    },
    "method_not_allowed": {
      "source": "platform/api/durable-run-service.mjs · platform/api/durable-runs.mjs",
      "statuses": [
        405
      ]
    },
    "model_entitlement_sync_pending": {
      "source": "platform/api/server.mjs keyModelsForApi",
      "statuses": [
        503
      ]
    },
    "model_not_allowed": {
      "source": "platform/api/images-authorize.mjs",
      "statuses": [
        403
      ]
    },
    "model_not_found": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor · platform/litellm/typed_errors.py GATEWAY_TYPED_CODES (a registry miss is final, never a retried 502)",
      "statuses": [
        400
      ]
    },
    "model_policy_conflict": {
      "source": "platform/api/model-aliases.mjs (`ModelPolicyError`'s DEFAULT code — no literal to scan; its named siblings are scanned from the same file) · platform/api/server.mjs keyModelsForApi (`openaiErrBody(error.code)`, the OpenAI `permission_error` type)",
      "statuses": [
        403
      ]
    },
    "model_required": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "model_variance": {
      "source": "platform/litellm/model_variance.py",
      "statuses": [
        500
      ]
    },
    "no_capacity": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor · portal-gateway/server.mjs handleImages",
      "statuses": [
        429,
        503
      ]
    },
    "no_upstream": {
      "source": "platform/nginx/api.portal.ai.conf",
      "statuses": [
        503
      ]
    },
    "output_limit_exceeded": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        400
      ]
    },
    "portal_image_limit_reached": {
      "source": "portal-gateway/web-tools-store.mjs reserveImageOperation",
      "statuses": [
        429
      ]
    },
    "portal_web_incomplete": {
      "source": "portal-gateway/web-tools.mjs · server.mjs (`portalWebError`), mapped by httpErrorFor",
      "statuses": [
        502
      ]
    },
    "portal_web_timeout": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor (`code: err.portalWebError`; the web-assisted answer's timeout)",
      "statuses": [
        504
      ]
    },
    "premium_pool_exhausted": {
      "source": "platform/litellm/typed_errors.py GATEWAY_TYPED_CODES (every premium seat for the model is out of quota; Retry-After)",
      "statuses": [
        429
      ]
    },
    "process_canary_not_admitted": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        403
      ]
    },
    "rate_limit_exceeded": {
      "source": "portal-gateway/honest-429.mjs honest429Body · portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        429
      ]
    },
    "reasoning_limit_exceeded": {
      "source": "portal-gateway/reasoning-limit.mjs limitError",
      "statuses": [
        400
      ]
    },
    "relay_retiring": {
      "source": "platform/api/durable-run-service.mjs · platform/api/durable-runs.mjs",
      "statuses": [
        503
      ]
    },
    "request_too_large": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        413
      ]
    },
    "response_schema_mismatch": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        502
      ]
    },
    "run_authority_required": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        400
      ]
    },
    "run_authorization_changed": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        403
      ]
    },
    "run_budget_exceeded": {
      "source": "platform/litellm/typed_errors.py GATEWAY_TYPED_CODES (the gateway's chat-run turn/output-token budget; relayed unchanged, not billed)",
      "statuses": [
        502
      ]
    },
    "run_commit_unknown": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        503
      ]
    },
    "run_control_unavailable": {
      "source": "platform/api/durable-control-client.mjs",
      "statuses": [
        503
      ]
    },
    "run_delivery_reconciliation_pending": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        503
      ]
    },
    "run_event_missing": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        409
      ]
    },
    "run_event_read_too_large": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        413
      ]
    },
    "run_expired": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        410
      ]
    },
    "run_format_mismatch": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "run_id_conflict": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        409
      ]
    },
    "run_idle_timeout": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        504
      ]
    },
    "run_not_found": {
      "source": "platform/api/durable-runs.mjs · platform/api/durable-runtime.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        404
      ]
    },
    "run_not_terminal": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        409
      ]
    },
    "run_reader_unavailable": {
      "source": "platform/api/durable-control-client.mjs",
      "statuses": [
        503
      ]
    },
    "run_rejected_before_dispatch": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        409
      ]
    },
    "run_request_too_large": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        413
      ]
    },
    "run_result_unavailable": {
      "source": "platform/api/durable-runs.mjs",
      "statuses": [
        503
      ]
    },
    "run_state_invalid": {
      "source": "portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        503
      ]
    },
    "run_storage_unavailable": {
      "source": "platform/api/durable-runtime.mjs · portal-gateway/run-store.mjs (through the relay)",
      "statuses": [
        503
      ]
    },
    "stream_not_enabled": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "stream_required": {
      "source": "platform/litellm/long_requests.py",
      "statuses": [
        400
      ]
    },
    "timeout": {
      "source": "portal-gateway/image-gen.mjs",
      "statuses": [
        504
      ]
    },
    "unauthorized": {
      "source": "platform/api/durable-run-service.mjs · platform/api/images-authorize.mjs · platform/api/server.mjs keyModelsForApi · platform/nginx/api.portal.ai.conf",
      "statuses": [
        401
      ]
    },
    "unsupported_endpoint": {
      "source": "portal-gateway/server.mjs handleImages",
      "statuses": [
        404
      ]
    },
    "unsupported_input": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_media_type": {
      "source": "portal-gateway/server.mjs handleImages",
      "statuses": [
        415
      ]
    },
    "unsupported_parameter": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_previous_response_id": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_reasoning": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_response_schema": {
      "source": "portal-gateway/output-contract.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_store": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_text": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_tool_choice": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "unsupported_tools": {
      "source": "portal-gateway/run-wire.mjs",
      "statuses": [
        400
      ]
    },
    "upstream_error": {
      "source": "portal-gateway/openai-response.mjs httpErrorFor",
      "statuses": [
        502
      ]
    },
    "wallet_commit_unknown": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        503
      ]
    },
    "wallet_insufficient_credit": {
      "source": "platform/api/durable-run-wallet.mjs (`fail('wallet_insufficient_credit', 402)`), relayed by durable-control-client.mjs on a durable creation",
      "statuses": [
        402
      ]
    },
    "wallet_post_commit_sync_failed": {
      "source": "platform/api/durable-runtime.mjs",
      "statuses": [
        503
      ]
    }
  },
  "x-portal-generated": {
    "docs": "https://platform.portal.ai/docs.html",
    "from": [
      "platform/api/durable-runs.mjs (CREATE_PATHS · REPLAY_PATH · REPLAY_ACTIONS)",
      "platform/nginx/api.portal.ai.conf (location = · the JSON error pages)",
      "portal-gateway/run-wire.mjs (RUN_RETENTION_SECONDS · PUBLIC_RUN_STATUSES)",
      "typed error literals: SCANNED_SOURCES · STORE_ERROR_CODES · EDGE_SCANS · EDGE_ERROR_CODES (hand rows for dynamic families)"
    ]
  }
}
