{
  "openapi": "3.1.0",
  "info": {
    "title": "Agent ID (id.8004.im)",
    "version": "1.0.0",
    "description": "Sign-in, API keys, grants and encryption keys for ERC-8004 agents."
  },
  "servers": [
    {
      "url": "https://id.8004.im"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "id token (JWT) or API key (ak_…)"
      }
    }
  },
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/auth/challenge": {
      "post": {
        "summary": "Get a SIWE message to sign",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "address": {
                    "type": "string"
                  },
                  "chain": {
                    "type": "string"
                  },
                  "agents": {
                    "type": "array"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "address",
                  "agents"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/auth/verify": {
      "post": {
        "summary": "Sign in: one token per agent",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string"
                  },
                  "signature": {
                    "type": "string"
                  },
                  "cookie": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "message",
                  "signature"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/auth/logout": {
      "post": {
        "summary": "End the web session",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/auth/logout-all": {
      "post": {
        "summary": "Revoke every token, API key and grant of the agent (epoch bump)",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/token": {
      "post": {
        "summary": "Trade a session / API key for a 1 h token",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "aud": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": []
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "summary": "Who am I, for which agent",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/agents": {
      "get": {
        "summary": "Agents a wallet controls (from the 8004 index)",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "security": [],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/scopes": {
      "get": {
        "summary": "Tool registry and scopes",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "security": []
      }
    },
    "/v1/keys": {
      "get": {
        "summary": "List API keys",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "Create an API key (shown once)",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "expires_days": {
                    "type": "number"
                  }
                },
                "required": [
                  "name",
                  "scopes"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/keys/{id}": {
      "delete": {
        "summary": "Revoke an API key",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/grants": {
      "get": {
        "summary": "Grants this agent gave",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "summary": "Give part of this agent's access to another agent or service",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "grantee_kind": {
                    "type": "string"
                  },
                  "grantee": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "expires_days": {
                    "type": "number"
                  },
                  "max_uses": {
                    "type": "number"
                  },
                  "constraints": {
                    "type": "object"
                  },
                  "name": {
                    "type": "string"
                  }
                },
                "required": [
                  "grantee_kind",
                  "grantee",
                  "scopes"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/grants/received": {
      "get": {
        "summary": "Grants this agent holds",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/grants/{id}": {
      "delete": {
        "summary": "Revoke a grant",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/v1/token/exchange": {
      "post": {
        "summary": "Grantee: get a token acting for the grantor",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "for": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "aud": {
                    "type": "string"
                  },
                  "grant": {
                    "type": "string"
                  }
                },
                "required": [
                  "for"
                ]
              }
            }
          }
        }
      }
    },
    "/v1/log": {
      "get": {
        "summary": "Access log",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "number"
            }
          }
        ]
      }
    },
    "/v1/tools": {
      "get": {
        "summary": "Tools with keys for this agent",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/wipe": {
      "post": {
        "summary": "Wipe one tool, or everything",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tool": {
                    "type": "string"
                  },
                  "all": {
                    "type": "boolean"
                  },
                  "confirm": {
                    "type": "string"
                  }
                },
                "required": []
              }
            }
          }
        }
      }
    },
    "/.well-known/jwks.json": {
      "get": {
        "summary": "Token public keys",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "security": []
      }
    }
  }
}