{
  "openapi": "3.1.0",
  "info": {
    "title": "Modern Saray Machine API",
    "version": "1.1.0",
    "description": "MODERN SARAY machine API. Existing keys and compatibility origins remain supported. Agent credentials support account and workspace delegation. Agent Passport is a proprietary Ed25519-signed registry identity, not runtime attestation or API authority. Human controls: https://modernsaray.com/work.html. Online verification rechecks expiry, revocation and delegation."
  },
  "servers": [
    {
      "url": "https://api.modernsaray.com",
      "description": "Primary machine API origin"
    },
    {
      "url": "https://modernsaray.com/api",
      "description": "Existing same-origin compatibility path"
    },
    {
      "url": "https://omerazizozdemir.com/api",
      "description": "Legacy compatibility origin"
    }
  ],
  "externalDocs": {
    "url": "https://modernsaray.com/docs.html"
  },
  "paths": {
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List accessible model IDs",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response. Fields depend on the operation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Scope, IP or browser-origin restriction"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Account or operation conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Service error"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create a chat completion",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response. Fields depend on the operation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                },
                "example": "data: {\"choices\":[{\"delta\":{\"content\":\"Hello\"}}]}\n\ndata: [DONE]\n\n"
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Scope, IP or browser-origin restriction"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Account or operation conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Service error"
          },
          "400": {
            "description": "Invalid chat input or idempotency key reused with a different payload"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Optional. Reuse only with the same payload and X-Megaverse-Session. Completed requests replay without another charge across compatible origins. In-progress requests return 409; payload mismatch returns 400.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/external/chat": {
      "post": {
        "operationId": "createExternalChat",
        "summary": "Send a message with optional conversation session",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response. Fields depend on the operation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Scope, IP or browser-origin restriction"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Account or operation conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Service error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExternalChatRequest"
              }
            }
          }
        }
      }
    },
    "/v1/external/me": {
      "get": {
        "operationId": "getApiAccount",
        "summary": "Inspect the account associated with the API key; not Agent Passport",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response. Fields depend on the operation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Scope, IP or browser-origin restriction"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Account or operation conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Service error"
          }
        }
      }
    },
    "/v1/external/usage": {
      "get": {
        "operationId": "getApiUsage",
        "summary": "Inspect private API usage and wallet status",
        "security": [
          {
            "ApiKeyBearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response. Fields depend on the operation.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "403": {
            "description": "Scope, IP or browser-origin restriction"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Account or operation conflict"
          },
          "422": {
            "description": "Invalid request"
          },
          "429": {
            "description": "Rate limit exceeded"
          },
          "500": {
            "description": "Service error"
          }
        }
      }
    },
    "/v1/agents/self/passport": {
      "get": {
        "tags": [
          "agent-access"
        ],
        "summary": "Passport",
        "operationId": "passport_v1_agents_self_passport_get",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid, expired or revoked agent credential"
          },
          "403": {
            "description": "Scope, IP or account denied; browser Origin prohibited"
          },
          "429": {
            "description": "Delegation or account request limit exceeded"
          }
        },
        "security": [
          {
            "AgentBearer": []
          }
        ],
        "description": "Requires passport:read. Returns a short-lived Ed25519-signed identity using the proprietary modern-saray.agent-passport.v2 profile. This is NOT runtime attestation or an API credential. Verify with POST /v1/passports/verify."
      }
    },
    "/v1/agents/self/capabilities": {
      "get": {
        "tags": [
          "agent-access"
        ],
        "summary": "Capabilities",
        "operationId": "capabilities_v1_agents_self_capabilities_get",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid, expired or revoked agent credential"
          },
          "403": {
            "description": "Scope, IP or account denied; browser Origin prohibited"
          },
          "429": {
            "description": "Delegation or account request limit exceeded"
          }
        },
        "security": [
          {
            "AgentBearer": []
          }
        ],
        "description": "Requires passport:read. Private authenticated agent document; not a signed runtime attestation."
      }
    },
    "/v1/agents/self/models": {
      "get": {
        "tags": [
          "agent-access"
        ],
        "summary": "Models",
        "operationId": "models_v1_agents_self_models_get",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid, expired or revoked agent credential"
          },
          "403": {
            "description": "Scope, IP or account denied; browser Origin prohibited"
          },
          "429": {
            "description": "Delegation or account request limit exceeded"
          }
        },
        "security": [
          {
            "AgentBearer": []
          }
        ],
        "description": "Requires models:read. Private authenticated agent document; not a signed runtime attestation."
      }
    },
    "/v1/agents/self/chat/completions": {
      "post": {
        "tags": [
          "agent-access"
        ],
        "summary": "Chat",
        "operationId": "chat_v1_agents_self_chat_completions_post",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid, expired or revoked agent credential"
          },
          "403": {
            "description": "Scope, IP or account denied; browser Origin prohibited"
          },
          "429": {
            "description": "Delegation or account request limit exceeded"
          },
          "400": {
            "description": "Missing idempotency key, streaming requested, or invalid input"
          },
          "402": {
            "description": "Insufficient API wallet balance"
          },
          "409": {
            "description": "Request already processing or provider unavailable"
          },
          "413": {
            "description": "Input too large"
          }
        },
        "security": [
          {
            "AgentBearer": []
          }
        ],
        "description": "Requires chat:complete. Non-streaming only, max 32,000 message characters. max_tokens must be between 16 and grant max_output_tokens. Uses owner API wallet. Retries require same Idempotency-Key. All admitted HTTP requests including replays count toward delegation request limits."
      }
    },
    "/.well-known/jwks.json": {
      "get": {
        "summary": "Agent Passport public signing keys (JWKS)",
        "responses": {
          "200": {
            "description": "Ed25519 public keys only"
          }
        }
      }
    },
    "/v1/passports/verify": {
      "post": {
        "summary": "Verify signed identity and current delegation",
        "description": "Does not authorize capability execution. Fixed issuer, audience and type; max 5-minute lifetime. Revoked, malformed or expired tokens return valid:false. Rate limited per IP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "passport"
                ],
                "additionalProperties": false,
                "properties": {
                  "passport": {
                    "type": "string",
                    "minLength": 32,
                    "maxLength": 4096
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Identity verification result; runtime_attested:false for valid tokens"
          },
          "429": {
            "description": "Verification rate limited"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from the authenticated developer portal. Keep it server-side."
      },
      "AgentBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Delegated msa_agent_ credential created in the human developer panel. Never ship to browsers."
      }
    },
    "schemas": {
      "ChatMessage": {
        "properties": {
          "role": {
            "type": "string",
            "pattern": "^(system|developer|user|assistant|tool)$",
            "title": "Role"
          },
          "content": {
            "type": "string",
            "title": "Content"
          }
        },
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "title": "ChatMessage"
      },
      "ChatCompletionRequest": {
        "properties": {
          "model": {
            "type": "string",
            "title": "Model",
            "default": "modern-saray"
          },
          "messages": {
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            },
            "type": "array",
            "maxItems": 100,
            "minItems": 1,
            "title": "Messages"
          },
          "stream": {
            "type": "boolean",
            "title": "Stream",
            "default": false
          },
          "temperature": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ],
            "title": "Temperature"
          },
          "max_tokens": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Max Tokens"
          },
          "user": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 200
              },
              {
                "type": "null"
              }
            ],
            "title": "User"
          }
        },
        "type": "object",
        "required": [
          "messages"
        ],
        "title": "ChatCompletionRequest"
      },
      "ExternalChatRequest": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "minLength": 1,
            "maxLength": 12000
          },
          "session_id": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          }
        }
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    }
  }
}