{
  "openapi": "3.0.3",
  "info": {
    "title": "Agent wallet and model API",
    "version": "1.0.0",
    "description": "Autonomous wallet login and prepaid model API. Native USDC on Arbitrum One only. Direct ERC-20 transfers, not x402. Powered by new-api by QuantumNous."
  },
  "servers": [
    {
      "url": "/",
      "description": "Use the origin serving this document."
    }
  ],
  "paths": {
    "/.well-known/agent.json": {
      "get": {
        "operationId": "discoverAgentAPI",
        "summary": "Read live availability and endpoint links",
        "responses": {
          "200": {
            "description": "Live manifest",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/auth/challenge": {
      "post": {
        "operationId": "createWalletChallenge",
        "summary": "Get a one-time EIP-4361 message",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "wallet": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{40}$"
                  }
                },
                "required": [
                  "wallet"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "flow_token": {
                      "type": "string",
                      "description": "Opaque challenge handle"
                    },
                    "message": {
                      "type": "string",
                      "description": "Sign these exact UTF-8 bytes with personal_sign"
                    },
                    "expires_at": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "signature_method": {
                      "type": "string",
                      "enum": [
                        "personal_sign"
                      ]
                    }
                  },
                  "required": [
                    "flow_token",
                    "message",
                    "expires_at",
                    "signature_method"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/auth/verify": {
      "post": {
        "operationId": "signInWithWallet",
        "summary": "Register a zero-credit account or sign in using an EOA signature",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "flow_token": {
                    "type": "string",
                    "maxLength": 128
                  },
                  "signature": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{130}$"
                  }
                },
                "required": [
                  "flow_token",
                  "signature"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access_token": {
                      "type": "string",
                      "description": "Agent token; not a model API key"
                    },
                    "token_type": {
                      "type": "string",
                      "enum": [
                        "Bearer"
                      ]
                    },
                    "expires_at": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "user_id": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "created": {
                      "type": "boolean"
                    },
                    "wallet": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    }
                  },
                  "required": [
                    "access_token",
                    "token_type",
                    "expires_at",
                    "user_id",
                    "created",
                    "wallet"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/me": {
      "get": {
        "operationId": "getAgentBalance",
        "summary": "Read account balance",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user_id": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "wallet": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "balance": {
                      "type": "object",
                      "properties": {
                        "quota": {
                          "type": "integer",
                          "format": "int64"
                        },
                        "usd": {
                          "type": "string",
                          "description": "Current USD balance"
                        },
                        "currency": {
                          "type": "string",
                          "enum": [
                            "USD"
                          ]
                        },
                        "quota_per_usd": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "quota",
                        "usd",
                        "currency",
                        "quota_per_usd"
                      ]
                    }
                  },
                  "required": [
                    "user_id",
                    "wallet",
                    "balance"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/pricing": {
      "get": {
        "operationId": "getAgentPricing",
        "summary": "Read live model catalog and prices filtered by usable groups",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/tokens": {
      "get": {
        "operationId": "listAgentKeys",
        "summary": "List up to 100 owned API keys without revealing secrets",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAgentKey",
        "summary": "Create a bounded, expiring model API key",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 50
                  },
                  "budget_usd": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]{0,4}$",
                    "description": "Whole USD, 1–10000. Both key and real account balance limits apply."
                  },
                  "expires_in_seconds": {
                    "type": "integer",
                    "minimum": 60,
                    "maximum": 2592000,
                    "default": 86400
                  },
                  "models": {
                    "type": "array",
                    "maxItems": 64,
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    }
                  }
                },
                "required": [
                  "budget_usd"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "api_key": {
                      "type": "string",
                      "description": "Save once, securely; use as Bearer credential for /v1/*"
                    },
                    "expires_at": {
                      "type": "integer",
                      "format": "int64"
                    },
                    "budget_usd": {
                      "type": "string",
                      "description": "Spending limit"
                    },
                    "models": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "required": [
                    "id",
                    "api_key",
                    "expires_at",
                    "budget_usd",
                    "models"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/tokens/{id}": {
      "delete": {
        "operationId": "revokeAgentKey",
        "summary": "Revoke an owned model API key",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Key revoked"
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/deposits": {
      "post": {
        "operationId": "createUSDCDeposit",
        "summary": "Create or replay an immutable deposit quote before sending USDC",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usdc": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]{0,3}$",
                    "description": "Whole native USDC, 1–1000."
                  }
                },
                "required": [
                  "amount_usdc"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent replay of existing order",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deposit"
                }
              }
            }
          },
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deposit"
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128
            },
            "description": "Persist and reuse for retries of the same deposit and amount."
          }
        ]
      }
    },
    "/api/agent/deposits/{order_id}": {
      "get": {
        "operationId": "getUSDCDeposit",
        "summary": "Poll persisted payment state (30-second interval)",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deposit"
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ]
      }
    },
    "/api/agent/deposits/{order_id}/confirm": {
      "post": {
        "operationId": "confirmUSDCDeposit",
        "summary": "Verify the direct USDC transfer; never repay on a timeout",
        "security": [
          {
            "AgentAccess": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "transaction_hash": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{64}$"
                  }
                },
                "required": [
                  "transaction_hash"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deposit"
                }
              }
            }
          },
          "202": {
            "description": "Receipt unavailable: retry confirm with the same hash. Confirming order: poll status until paid. Never send a second payment.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Deposit"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          }
        ]
      }
    },
    "/v1/models": {
      "get": {
        "operationId": "listAvailableModels",
        "summary": "List models available to a model API key",
        "security": [
          {
            "ModelKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OpenAI-compatible model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "object",
                    "data"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Call an available model using prepaid account balance and key budget",
        "security": [
          {
            "ModelKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "max_tokens": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1073741823
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "required": [
                  "model",
                  "messages"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OpenAI-compatible completion, or SSE when stream=true",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Request rejected; inspect error.code and honor Retry-After.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "AgentAccess": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Obtained via wallet challenge/verify. Expires after 15 minutes; sign in again on 401."
      },
      "ModelKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk-...",
        "description": "Obtained from POST /api/agent/tokens; cannot manage the agent account."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "Deposit": {
        "type": "object",
        "properties": {
          "order": {
            "type": "object",
            "properties": {
              "order_id": {
                "type": "string"
              },
              "network": {
                "type": "string",
                "enum": [
                  "eip155:42161"
                ]
              },
              "asset": {
                "type": "string",
                "pattern": "^0x[0-9a-fA-F]{40}$"
              },
              "pay_to": {
                "type": "string",
                "pattern": "^0x[0-9a-fA-F]{40}$"
              },
              "payer": {
                "type": "string",
                "pattern": "^0x[0-9a-fA-F]{40}$"
              },
              "amount_usdc": {
                "type": "string"
              },
              "amount_atomic": {
                "type": "string"
              },
              "credit_quota": {
                "type": "integer",
                "format": "int64"
              },
              "start_block": {
                "type": "integer",
                "format": "int64"
              },
              "created_at": {
                "type": "integer",
                "format": "int64"
              },
              "expires_at": {
                "type": "integer",
                "format": "int64"
              },
              "status": {
                "type": "string",
                "enum": [
                  "pending",
                  "confirming",
                  "paid"
                ]
              },
              "transaction_hash": {
                "type": "string",
                "pattern": "^0x[0-9a-fA-F]{64}$"
              },
              "completed_at": {
                "type": "integer",
                "format": "int64"
              }
            },
            "required": [
              "order_id",
              "network",
              "asset",
              "pay_to",
              "payer",
              "amount_usdc",
              "amount_atomic",
              "credit_quota",
              "start_block",
              "created_at",
              "expires_at",
              "status"
            ]
          },
          "payment": {
            "type": "object",
            "properties": {
              "method": {
                "type": "string",
                "enum": [
                  "erc20_transfer"
                ]
              },
              "chain_id": {
                "type": "integer",
                "enum": [
                  42161
                ]
              },
              "token": {
                "type": "string",
                "enum": [
                  "USDC"
                ]
              },
              "decimals": {
                "type": "integer",
                "enum": [
                  6
                ]
              },
              "finality": {
                "type": "string",
                "enum": [
                  "finalized"
                ]
              },
              "transaction": {
                "type": "object",
                "properties": {
                  "chainId": {
                    "type": "integer",
                    "enum": [
                      42161
                    ]
                  },
                  "from": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{40}$"
                  },
                  "to": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{40}$"
                  },
                  "value": {
                    "type": "string",
                    "enum": [
                      "0x0"
                    ]
                  },
                  "data": {
                    "type": "string",
                    "description": "ERC-20 transfer calldata. Verify receiver and atomic amount before signing."
                  }
                },
                "required": [
                  "chainId",
                  "from",
                  "to",
                  "value",
                  "data"
                ]
              }
            },
            "required": [
              "method",
              "chain_id",
              "token",
              "decimals",
              "finality",
              "transaction"
            ]
          },
          "links": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string"
              },
              "confirm": {
                "type": "string"
              }
            },
            "required": [
              "status",
              "confirm"
            ]
          }
        },
        "required": [
          "order",
          "payment",
          "links"
        ]
      }
    }
  }
}
