{
  "openapi": "3.1.0",
  "info": {
    "title": "AIDC Developer API",
    "version": "1.1.1",
    "description": "Generated from src/server/api/contracts.ts — do not edit by hand. Envelope, error codes and guard semantics: docs/api-standards.md. Regenerate: npm run openapi:generate."
  },
  "security": [
    {
      "aidcSession": []
    }
  ],
  "paths": {
    "/api/v1/developer/device-codes": {
      "post": {
        "operationId": "v1.developer.device-codes.create",
        "summary": "Start an aidc CLI device login (RFC 8628 semantics): returns deviceCode (kept by the CLI), userCode and the verification URI a signed-in developer opens to approve.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "rate_limited",
          "malformed_json",
          "invalid_payload",
          "payload_too_large"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "clientName": {
                    "default": "aidc CLI",
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/device-codes/decision": {
      "post": {
        "operationId": "v1.developer.device-codes.decision",
        "summary": "Signed-in developer approves or denies a pending CLI login and picks the company the issued developer key acts for (same-origin browser request).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "invalid_session",
          "forbidden",
          "rate_limited",
          "device_code_expired",
          "malformed_json",
          "invalid_payload"
        ],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "userCode": {
                    "type": "string",
                    "pattern": "^[BCDFGHJKLMNPQRSTVWXZ]{4}-[BCDFGHJKLMNPQRSTVWXZ]{4}$"
                  },
                  "decision": {
                    "type": "string",
                    "enum": [
                      "approve",
                      "deny"
                    ]
                  },
                  "cellId": {
                    "type": "string",
                    "maxLength": 64
                  }
                },
                "required": [
                  "userCode",
                  "decision"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/device-tokens": {
      "post": {
        "operationId": "v1.developer.device-tokens.exchange",
        "summary": "CLI polls with its deviceCode: authorization_pending until approved, then a one-time developer key (aidc-dk-…, plaintext only in this response). Polling faster than the interval returns rate_limited.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "authorization_pending",
          "access_denied",
          "device_code_expired",
          "rate_limited",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "deviceCode": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_-]{32,128}$"
                  }
                },
                "required": [
                  "deviceCode"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/me": {
      "get": {
        "operationId": "v1.developer.me",
        "summary": "Identity behind a developer key: account, company it acts for, key prefix and writable app namespaces.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized"
        ],
        "security": [],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "required": true,
            "description": "Developer key",
            "schema": {
              "type": "string",
              "pattern": "^Bearer aidc-dk-"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/keys": {
      "get": {
        "operationId": "v1.developer.keys",
        "summary": "Developer keys issued by the caller (prefix only). Accepts a developer key or a signed-in session.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/keys/{keyId}": {
      "delete": {
        "operationId": "v1.developer.keys.revoke",
        "summary": "Revoke one of the caller's developer keys (idempotent).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "invalid_path",
          "agent_key_not_found",
          "forbidden"
        ],
        "security": [],
        "parameters": [
          {
            "name": "keyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/apps": {
      "get": {
        "operationId": "v1.developer.apps",
        "summary": "Nexus apps visible to the developer key: its company's namespace, plus the official public namespace for AIDC platform keys.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/apps/{namespace}/{slug}": {
      "get": {
        "operationId": "v1.developer.apps.get",
        "summary": "One app: test/production channel pointers, version history (digest, size, tested) and its Developer / Nexus URLs.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "invalid_path",
          "forbidden",
          "app_not_found"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/apps/{namespace}/{slug}/versions": {
      "post": {
        "operationId": "v1.developer.apps.versions.create",
        "summary": "Upload a version bundle (manifest + files). Every version carries a semantic version number (manifest.version); content-addressed: identical files return the existing version (200) instead of creating one (201) — retries are idempotent; changed content under an already-used version number is refused (409 version_conflict). x-aidc-dry-run: true returns 202 with the plan.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "invalid_path",
          "forbidden",
          "bundle_invalid",
          "version_conflict",
          "malformed_json",
          "invalid_payload",
          "payload_too_large"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "manifest": {
                    "type": "object",
                    "properties": {
                      "$schema": {
                        "type": "string",
                        "maxLength": 200
                      },
                      "manifestVersion": {
                        "type": "number",
                        "const": 1
                      },
                      "slug": {
                        "type": "string",
                        "pattern": "^[a-z][a-z0-9-]{1,47}$"
                      },
                      "version": {
                        "type": "string",
                        "pattern": "^(0|[1-9]\\d{0,5})\\.(0|[1-9]\\d{0,5})\\.(0|[1-9]\\d{0,5})(-[0-9A-Za-z.-]{1,32})?$"
                      },
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 60
                      },
                      "summary": {
                        "default": "",
                        "type": "string",
                        "maxLength": 240
                      },
                      "category": {
                        "default": "general",
                        "type": "string",
                        "enum": [
                          "vision",
                          "voice",
                          "video",
                          "data",
                          "agent",
                          "general"
                        ]
                      },
                      "namespace": {
                        "type": "string",
                        "pattern": "^(public|cell-[a-z0-9][a-z0-9-]{1,62})$"
                      },
                      "entry": {
                        "default": "index.html",
                        "type": "string",
                        "maxLength": 120,
                        "pattern": "^[a-z0-9][a-z0-9._/-]*\\.html$"
                      },
                      "sdk": {
                        "default": [],
                        "maxItems": 6,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "enum": [
                            "vision",
                            "voice",
                            "video",
                            "model",
                            "data",
                            "connect"
                          ]
                        }
                      },
                      "permissions": {
                        "default": {
                          "camera": false,
                          "microphone": false
                        },
                        "type": "object",
                        "properties": {
                          "camera": {
                            "default": false,
                            "type": "boolean"
                          },
                          "microphone": {
                            "default": false,
                            "type": "boolean"
                          }
                        },
                        "additionalProperties": false
                      },
                      "models": {
                        "default": [],
                        "maxItems": 12,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 64
                        }
                      },
                      "datasets": {
                        "default": [],
                        "maxItems": 12,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 64
                        }
                      },
                      "streams": {
                        "default": [],
                        "maxItems": 12,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "pattern": "^[a-z][a-z0-9-]{1,47}$"
                        }
                      },
                      "agents": {
                        "default": false,
                        "type": "boolean"
                      },
                      "storage": {
                        "default": {
                          "type": "none"
                        },
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "none"
                          }
                        },
                        "required": [
                          "type"
                        ],
                        "additionalProperties": false
                      },
                      "limits": {
                        "default": {
                          "dailyTokens": 1000000,
                          "requestsPerMinute": 30,
                          "realtimeSessionsPerDay": 100
                        },
                        "type": "object",
                        "properties": {
                          "dailyTokens": {
                            "default": 1000000,
                            "type": "integer",
                            "minimum": 1000,
                            "maximum": 50000000
                          },
                          "requestsPerMinute": {
                            "default": 30,
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 600
                          },
                          "realtimeSessionsPerDay": {
                            "default": 100,
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 5000
                          }
                        },
                        "additionalProperties": false
                      },
                      "cdn": {
                        "default": [],
                        "maxItems": 2,
                        "type": "array",
                        "items": {
                          "type": "string",
                          "enum": [
                            "cdn.jsdelivr.net",
                            "cdnjs.cloudflare.com"
                          ]
                        }
                      }
                    },
                    "required": [
                      "manifestVersion",
                      "slug",
                      "version",
                      "title"
                    ],
                    "additionalProperties": false
                  },
                  "files": {
                    "minItems": 1,
                    "maxItems": 200,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "path": {
                          "type": "string",
                          "pattern": "^(?!.*(?:^|\\/)\\.)(?!.*\\.\\.)[A-Za-z0-9_\\-][A-Za-z0-9_\\-./]{0,199}$"
                        },
                        "encoding": {
                          "type": "string",
                          "enum": [
                            "utf8",
                            "base64"
                          ]
                        },
                        "content": {
                          "type": "string",
                          "maxLength": 5242880
                        }
                      },
                      "required": [
                        "path",
                        "encoding",
                        "content"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "manifest",
                  "files"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/apps/{namespace}/{slug}/channels/{channel}": {
      "post": {
        "operationId": "v1.developer.apps.channels.promote",
        "summary": "Point a channel (test | production) at a version (semantic version number or build number). Idempotent. production only accepts versions that have been on test (defaults to the current test version); naming an earlier tested version rolls back. Every change is recorded in the release history (action test | release | rollback, notes). Supports x-aidc-dry-run.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "invalid_path",
          "forbidden",
          "app_not_found",
          "app_version_not_found",
          "version_not_tested",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "channel",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "exclusiveMinimum": 0,
                        "maximum": 9007199254740991
                      },
                      {
                        "type": "string",
                        "pattern": "^(0|[1-9]\\d{0,5})\\.(0|[1-9]\\d{0,5})\\.(0|[1-9]\\d{0,5})(-[0-9A-Za-z.-]{1,32})?$"
                      }
                    ]
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/apps/{namespace}/{slug}/tickets": {
      "post": {
        "operationId": "v1.developer.apps.tickets.create",
        "summary": "Renew the short-lived app ticket (aidc-at-…) the browser SDK uses. Public apps: anonymous, same-origin, rate limited per IP; company apps: signed-in member (production) or developer (test).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "invalid_path",
          "forbidden",
          "invalid_session",
          "rate_limited",
          "app_not_found",
          "live_unconfigured"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "channel",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "test",
                "production"
              ],
              "default": "production"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/datasets": {
      "get": {
        "operationId": "v1.developer.datasets",
        "summary": "Datasets the caller may read (developer key: public datasets; app ticket: datasets declared in the app manifest).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/datasets/{datasetId}/reports/{reportId}": {
      "get": {
        "operationId": "v1.developer.datasets.reports.get",
        "summary": "Fixed-format report of a dataset — aggregates only, never row-level data (e.g. aidc-demo-erp/overview: KPIs, monthly trend, customers, AR ageing, inventory risk, rule-based signals).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "dataset_not_found",
          "report_not_found",
          "rate_limited"
        ],
        "security": [],
        "parameters": [
          {
            "name": "datasetId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/streams": {
      "get": {
        "operationId": "v1.developer.streams.list",
        "summary": "Connect SDK data streams of the caller's company (plus public for AIDC staff), with publisher status (ok | degraded | source_unreachable | stopped, last seen, live).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "v1.developer.streams.declare",
        "summary": "Declare a data stream (idempotent upsert): name, optional row key, field allowlist (published rows/events may only carry these fields; sensitive categories refused), event retention. Supports x-aidc-dry-run.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "stream_conflict",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9-]{1,47}$"
                  },
                  "namespace": {
                    "type": "string",
                    "pattern": "^(public|cell-[a-z0-9][a-z0-9-]{1,62})$"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  },
                  "summary": {
                    "default": "",
                    "type": "string",
                    "maxLength": 240
                  },
                  "key": {
                    "type": "string",
                    "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"
                  },
                  "fields": {
                    "minItems": 1,
                    "maxItems": 64,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$"
                        },
                        "type": {
                          "default": "string",
                          "type": "string",
                          "enum": [
                            "string",
                            "number",
                            "boolean",
                            "datetime",
                            "json"
                          ]
                        },
                        "label": {
                          "type": "string",
                          "maxLength": 40
                        }
                      },
                      "required": [
                        "name"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "retention": {
                    "default": 1000,
                    "type": "integer",
                    "minimum": 10,
                    "maximum": 10000
                  }
                },
                "required": [
                  "name",
                  "title",
                  "fields"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/streams/{namespace}/{name}": {
      "get": {
        "operationId": "v1.developer.streams.get",
        "summary": "A data stream and its latest materialized state (rows keyed by the stream key, or a single value). Readable with a developer key of the company or an app ticket whose manifest declares the stream.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "v1.developer.streams.delete",
        "summary": "Delete a data stream: its event log and state are physically deleted and its publish keys revoked. Supports x-aidc-dry-run.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/streams/{namespace}/{name}/events": {
      "get": {
        "operationId": "v1.developer.streams.events.subscribe",
        "summary": "Subscribe. Accept: text/event-stream (or ?sse=1) opens a Server-Sent Events stream: state (full state), change (patch), notice (event), publisher (publisher status), reconnect; every event carries id = sequence number and ?after=N (or Last-Event-ID) resumes without gaps. Without SSE returns JSON increments after N (reset=true with the full state when N is too old).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found",
          "rate_limited"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "sse",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "v1.developer.streams.events.publish",
        "summary": "Publish up to 100 events (snapshot | patch | event | status) with a publish key (aidc-pk-, one stream only) or a developer key. The whole batch is prechecked against the field allowlist; an event id seen before is dropped (idempotent retries); a status equal to the current one counts as a heartbeat. Each accepted event gets the next sequence number and wakes subscribers.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found",
          "stream_event_rejected",
          "rate_limited",
          "malformed_json",
          "invalid_payload",
          "payload_too_large"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "events": {
                    "minItems": 1,
                    "maxItems": 100,
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "snapshot"
                            },
                            "id": {
                              "type": "string",
                              "pattern": "^[A-Za-z0-9_.:-]{1,128}$"
                            },
                            "at": {
                              "type": "string",
                              "format": "date-time",
                              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                            },
                            "data": {
                              "anyOf": [
                                {
                                  "type": "object",
                                  "properties": {
                                    "rows": {
                                      "maxItems": 20000,
                                      "type": "array",
                                      "items": {
                                        "type": "object",
                                        "propertyNames": {
                                          "type": "string"
                                        },
                                        "additionalProperties": {}
                                      }
                                    }
                                  },
                                  "required": [
                                    "rows"
                                  ],
                                  "additionalProperties": false
                                },
                                {
                                  "type": "object",
                                  "properties": {
                                    "value": {
                                      "type": "object",
                                      "propertyNames": {
                                        "type": "string"
                                      },
                                      "additionalProperties": {}
                                    }
                                  },
                                  "required": [
                                    "value"
                                  ],
                                  "additionalProperties": false
                                }
                              ]
                            }
                          },
                          "required": [
                            "type",
                            "data"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "patch"
                            },
                            "id": {
                              "type": "string",
                              "pattern": "^[A-Za-z0-9_.:-]{1,128}$"
                            },
                            "at": {
                              "type": "string",
                              "format": "date-time",
                              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                            },
                            "data": {
                              "type": "object",
                              "properties": {
                                "upsert": {
                                  "default": [],
                                  "maxItems": 20000,
                                  "type": "array",
                                  "items": {
                                    "type": "object",
                                    "propertyNames": {
                                      "type": "string"
                                    },
                                    "additionalProperties": {}
                                  }
                                },
                                "delete": {
                                  "default": [],
                                  "maxItems": 20000,
                                  "type": "array",
                                  "items": {
                                    "anyOf": [
                                      {
                                        "type": "string",
                                        "minLength": 1,
                                        "maxLength": 200
                                      },
                                      {
                                        "type": "number"
                                      }
                                    ]
                                  }
                                }
                              },
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "type",
                            "data"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "event"
                            },
                            "id": {
                              "type": "string",
                              "pattern": "^[A-Za-z0-9_.:-]{1,128}$"
                            },
                            "at": {
                              "type": "string",
                              "format": "date-time",
                              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                            },
                            "data": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {}
                            }
                          },
                          "required": [
                            "type",
                            "data"
                          ],
                          "additionalProperties": false
                        },
                        {
                          "type": "object",
                          "properties": {
                            "type": {
                              "type": "string",
                              "const": "status"
                            },
                            "id": {
                              "type": "string",
                              "pattern": "^[A-Za-z0-9_.:-]{1,128}$"
                            },
                            "at": {
                              "type": "string",
                              "format": "date-time",
                              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                            },
                            "data": {
                              "type": "object",
                              "properties": {
                                "status": {
                                  "type": "string",
                                  "enum": [
                                    "ok",
                                    "degraded",
                                    "source_unreachable",
                                    "stopped"
                                  ]
                                },
                                "detail": {
                                  "type": "string",
                                  "maxLength": 300
                                }
                              },
                              "required": [
                                "status"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "required": [
                            "type",
                            "data"
                          ],
                          "additionalProperties": false
                        }
                      ]
                    }
                  }
                },
                "required": [
                  "events"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/developer/streams/{namespace}/{name}/keys": {
      "get": {
        "operationId": "v1.developer.streams.keys.list",
        "summary": "Publish keys of a stream (prefix, label, created, last used, revoked).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "v1.developer.streams.keys.issue",
        "summary": "Issue a publish key (aidc-pk-…) that can only publish to this stream — installed with the publisher on the customer side. The plaintext is returned once.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "stream_not_found",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  }
                },
                "required": [
                  "label"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "v1.developer.streams.keys.revoke",
        "summary": "Revoke a publish key by prefix (?prefix=aidc-pk-xxxxxxxx…).",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "invalid_path",
          "invalid_payload",
          "stream_not_found",
          "resource_not_found"
        ],
        "security": [],
        "parameters": [
          {
            "name": "namespace",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          },
          {
            "name": "prefix",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models": {
      "get": {
        "operationId": "v1.models.catalog",
        "summary": "AIDC model catalog for the Developer model SDK: models, inputs, endpoint, whether public apps may call them and whether the upstream is configured. OpenAI-compatible base URL: /api/v1/models.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/models": {
      "get": {
        "operationId": "v1.models.openai-list",
        "summary": "OpenAI-shaped model list (what OpenAI SDKs call as client.models.list() with base URL /api/v1/models). Registered §3 OpenAI-compatible exception.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/chat/completions": {
      "post": {
        "operationId": "v1.models.chat.completions",
        "summary": "OpenAI-compatible chat.completions (text, image_url, stream, response_format) billed to the caller's company: Bearer developer key (lane developer) or app ticket (lane app, manifest model allowlist, per-IP rate limit, daily token budget, output capped at 4096 tokens). Success is OpenAI-shaped (registered §3 exception); prompts transit only.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "model_not_found",
          "rate_limited",
          "quota_exhausted",
          "model_upstream_failed",
          "malformed_json",
          "invalid_payload",
          "payload_too_large"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  "messages": {
                    "minItems": 1,
                    "maxItems": 200,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "developer",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "anyOf": [
                            {
                              "type": "string",
                              "maxLength": 200000
                            },
                            {
                              "minItems": 1,
                              "maxItems": 16,
                              "type": "array",
                              "items": {
                                "oneOf": [
                                  {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "type": "string",
                                        "const": "text"
                                      },
                                      "text": {
                                        "type": "string",
                                        "maxLength": 200000
                                      }
                                    },
                                    "required": [
                                      "type",
                                      "text"
                                    ]
                                  },
                                  {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "type": "string",
                                        "const": "image_url"
                                      },
                                      "image_url": {
                                        "type": "object",
                                        "properties": {
                                          "url": {
                                            "type": "string",
                                            "maxLength": 7000000
                                          },
                                          "detail": {
                                            "type": "string",
                                            "enum": [
                                              "auto",
                                              "low",
                                              "high"
                                            ]
                                          }
                                        },
                                        "required": [
                                          "url"
                                        ]
                                      }
                                    },
                                    "required": [
                                      "type",
                                      "image_url"
                                    ]
                                  }
                                ]
                              }
                            }
                          ]
                        },
                        "name": {
                          "type": "string",
                          "maxLength": 64
                        }
                      },
                      "required": [
                        "role",
                        "content"
                      ]
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  },
                  "temperature": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "top_p": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "max_tokens": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 32000
                  },
                  "max_completion_tokens": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 32000
                  },
                  "reasoning_effort": {
                    "type": "string",
                    "enum": [
                      "minimal",
                      "low",
                      "medium",
                      "high"
                    ]
                  },
                  "response_format": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "text"
                          }
                        },
                        "required": [
                          "type"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "json_object"
                          }
                        },
                        "required": [
                          "type"
                        ]
                      },
                      {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "const": "json_schema"
                          },
                          "json_schema": {
                            "type": "object",
                            "properties": {
                              "name": {
                                "type": "string",
                                "pattern": "^[A-Za-z0-9_-]{1,64}$"
                              },
                              "schema": {
                                "type": "object",
                                "propertyNames": {
                                  "type": "string"
                                },
                                "additionalProperties": {}
                              },
                              "strict": {
                                "type": "boolean"
                              },
                              "description": {
                                "type": "string",
                                "maxLength": 500
                              }
                            },
                            "required": [
                              "name",
                              "schema"
                            ]
                          }
                        },
                        "required": [
                          "type",
                          "json_schema"
                        ]
                      }
                    ]
                  },
                  "user": {
                    "type": "string",
                    "maxLength": 128
                  }
                },
                "required": [
                  "model",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/audio/transcriptions": {
      "post": {
        "operationId": "v1.models.audio.transcriptions",
        "summary": "OpenAI-compatible audio.transcriptions (multipart/form-data: file ≤ 4 MB, model, language?, prompt?). Audio transits only; usage (seconds or tokens) is recorded against the caller's company.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "model_not_found",
          "invalid_payload",
          "payload_too_large",
          "rate_limited",
          "quota_exhausted",
          "model_upstream_failed"
        ],
        "security": [],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/realtime/transcription-sessions": {
      "post": {
        "operationId": "v1.models.realtime.transcription-sessions.create",
        "summary": "Mint a 10-minute client secret for realtime transcription (gpt-live-transcribe over WebRTC, session config pinned server-side, browser-side turn detection). Audio never passes through AIDC; sessions are capped at 5 minutes and counted per day for app tickets.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "rate_limited",
          "quota_exhausted",
          "model_upstream_failed",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "languages": {
                    "minItems": 1,
                    "maxItems": 5,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "zh",
                        "en",
                        "ja",
                        "ar",
                        "bn",
                        "ko",
                        "fr",
                        "de",
                        "es",
                        "ru",
                        "vi",
                        "th",
                        "id"
                      ]
                    }
                  },
                  "prompt": {
                    "type": "string",
                    "maxLength": 400,
                    "pattern": "^[^<>\\r\\n]*$"
                  },
                  "keywords": {
                    "maxItems": 30,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 40,
                      "pattern": "^[^<>\\r\\n]*$"
                    }
                  }
                },
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/jev/decisions": {
      "post": {
        "operationId": "v1.models.jev.decisions",
        "summary": "Jev (System 1) finite-choice decisions: each question lists candidate choices with criteria; returns the choice, confidence and probabilities. Metered by input tokens.",
        "x-aidc-min-role": "viewer",
        "x-aidc-error-codes": [
          "unauthorized",
          "forbidden",
          "rate_limited",
          "quota_exhausted",
          "model_upstream_failed",
          "malformed_json",
          "invalid_payload"
        ],
        "security": [],
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "state": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 20000
                      },
                      {
                        "type": "object",
                        "propertyNames": {
                          "type": "string"
                        },
                        "additionalProperties": {}
                      }
                    ]
                  },
                  "questions": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{0,31}$"
                    },
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "instructions": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 2000
                        },
                        "criteria": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string",
                            "pattern": "^[A-Za-z0-9_-]{1,40}$"
                          },
                          "additionalProperties": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 500
                          }
                        }
                      },
                      "required": [
                        "instructions",
                        "criteria"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "state",
                  "questions"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope (docs/api-standards.md §3).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiSuccess"
                }
              }
            }
          },
          "4XX": {
            "description": "Failure envelope; error.code is one of x-aidc-error-codes or a guard code (§4/§6).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          },
          "5XX": {
            "description": "Failure envelope (internal_error or downstream dependency failure).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiFailure"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "aidcSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "aidc_session",
        "description": "Opaque high-entropy first-party PersonalSession cookie. PostgreSQL stores only the SHA-256 token digest; expiry, revocation, account status, role and organizational scope are rechecked for authenticated requests."
      }
    },
    "schemas": {
      "ApiMeta": {
        "type": "object",
        "properties": {
          "requestId": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "version": {
            "type": "string"
          },
          "boundary": {
            "type": "string"
          }
        },
        "required": [
          "generatedAt"
        ]
      },
      "ApiSuccess": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "data": {},
          "meta": {
            "$ref": "#/components/schemas/ApiMeta"
          }
        },
        "required": [
          "ok",
          "data",
          "meta"
        ]
      },
      "ApiFailure": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "email_delivery_unavailable",
                  "email_verification_required",
                  "unauthorized",
                  "invalid_session",
                  "session_secret_not_configured",
                  "forbidden",
                  "idempotency_key_required",
                  "idempotency_conflict",
                  "live_gate_required",
                  "live_operation_disabled",
                  "approval_required",
                  "approval_pending",
                  "cell_mismatch",
                  "cell_not_allowed",
                  "malformed_json",
                  "invalid_payload",
                  "invalid_query_param",
                  "invalid_path",
                  "invalid_idempotency_key",
                  "payload_too_large",
                  "rate_limited",
                  "quota_exhausted",
                  "missing_customer_cellId",
                  "customer_not_registered",
                  "customer_not_found",
                  "agent_not_found",
                  "chain_not_found",
                  "report_not_found",
                  "dataset_not_found",
                  "share_not_found",
                  "share_grant_not_found",
                  "recipient_not_found",
                  "gate_failed",
                  "server_not_found",
                  "cell_unreachable",
                  "engine_failed",
                  "server_provider_not_configured",
                  "server_operation_failed",
                  "company_lifecycle_failed",
                  "health_check_unavailable",
                  "provisioning_failed",
                  "billing_order_not_found",
                  "server_billing_report_not_ready",
                  "server_billing_rebuild_failed",
                  "aws_instance_provisioning_failed",
                  "remote_bootstrap_failed",
                  "runtime_sync_failed",
                  "model_switch_failed",
                  "drive_unreachable",
                  "drive_operation_failed",
                  "file_not_found",
                  "file_too_large",
                  "resource_not_found",
                  "file_exists",
                  "not_editable",
                  "upload_not_found",
                  "upload_state_invalid",
                  "chunk_invalid",
                  "datasource_not_found",
                  "chat_records_unavailable",
                  "runtime_logs_unavailable",
                  "usage_unavailable",
                  "conversation_not_found",
                  "conversation_active",
                  "task_not_found",
                  "chat_transport_failed",
                  "stream_resumption_unavailable",
                  "agent_runtime_error",
                  "standard_not_found",
                  "position_exists",
                  "department_unresolved",
                  "standard_exists",
                  "license_tier_downgrade",
                  "routine_not_found",
                  "deployment_not_found",
                  "member_account_not_found",
                  "agent_key_not_found",
                  "agent_not_dispatchable",
                  "flash_provider_unconfigured",
                  "flash_persona_unavailable",
                  "flash_upstream_failed",
                  "flash_local_node_exclusive",
                  "live_unconfigured",
                  "live_session_failed",
                  "local_node_context_unavailable",
                  "forbidden_path",
                  "skills_unavailable",
                  "form_not_found",
                  "submission_not_found",
                  "submission_conflict",
                  "lead_not_found",
                  "personal_account_not_found",
                  "legacy_identity_resolution_required",
                  "username_taken",
                  "email_taken",
                  "operator_not_found",
                  "self_modification_forbidden",
                  "last_admin_protected",
                  "file_share_ownership_reassignment_required",
                  "clerk_not_configured",
                  "clerk_unavailable",
                  "department_not_found",
                  "position_not_found",
                  "agent_department_mismatch",
                  "invalid_credentials",
                  "account_locked",
                  "agent_not_granted",
                  "agent_card_not_found",
                  "agent_exists",
                  "mcp_server_not_found",
                  "mcp_operation_failed",
                  "messaging_channel_not_found",
                  "messaging_operation_failed",
                  "skills_operation_failed",
                  "runtime_config_failed",
                  "runtime_policy_failed",
                  "cron_health_failed",
                  "oidc_not_configured",
                  "oidc_state_invalid",
                  "oidc_exchange_failed",
                  "identity_not_bound",
                  "identity_already_bound",
                  "identity_not_found",
                  "entity_exists",
                  "entity_not_found",
                  "release_not_found",
                  "no_table",
                  "not_materialized",
                  "table_missing",
                  "instance_not_routable",
                  "authority_insufficient",
                  "minister_outside_department",
                  "minister_scope_department_only",
                  "minister_without_department",
                  "department_required",
                  "no_targets",
                  "actor_not_found",
                  "cell_unreachable",
                  "disk_exists",
                  "disk_not_found",
                  "profile_not_found",
                  "backend_unsupported",
                  "node_exists",
                  "node_not_found",
                  "internal_error",
                  "channel_bindings_disabled",
                  "target_not_bound",
                  "delivery_not_configured",
                  "enrollment_invalid",
                  "engine_artifact_unavailable",
                  "node_not_found",
                  "node_revoked",
                  "mesh_not_enrolled",
                  "mesh_peer_not_found",
                  "mesh_denied",
                  "mesh_pair_not_found",
                  "mesh_pair_state",
                  "command_not_found",
                  "fenced",
                  "node_offline",
                  "receiver_setup_failed",
                  "weak_password",
                  "company_not_found",
                  "license_not_found",
                  "license_invalid",
                  "license_plan_missing",
                  "license_plan_expired",
                  "license_quota_exceeded",
                  "app_not_found",
                  "app_version_not_found",
                  "version_not_tested",
                  "bundle_invalid",
                  "authorization_pending",
                  "device_code_expired",
                  "access_denied",
                  "model_not_found",
                  "model_upstream_failed",
                  "version_conflict",
                  "stream_not_found",
                  "stream_conflict",
                  "stream_event_rejected"
                ]
              },
              "message": {
                "type": "string"
              },
              "details": {}
            },
            "required": [
              "code",
              "message"
            ]
          },
          "meta": {
            "$ref": "#/components/schemas/ApiMeta"
          }
        },
        "required": [
          "ok",
          "error",
          "meta"
        ]
      }
    }
  }
}
