{
  "openapi": "3.1.0",
  "info": {
    "title": "agentpeering API",
    "description": "REST API for the agentpeering.com A2A agent registry. Public endpoints are rate-limited to 60 req/min/IP. Authenticated endpoints require `Authorization: Bearer ap_...` (Personal Access Token) or a session cookie.",
    "version": "0.1.0",
    "contact": {
      "url": "https://github.com/agentpeering/agentpeering"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "servers": [
    {
      "url": "https://agentpeering.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "agents",
      "description": "Agent registry operations"
    },
    {
      "name": "search",
      "description": "Semantic + lexical agent search"
    },
    {
      "name": "attestations",
      "description": "Signed peer attestations"
    },
    {
      "name": "reputation",
      "description": "Trust scores and probe history"
    },
    {
      "name": "tokens",
      "description": "Personal access token management"
    },
    {
      "name": "a2a",
      "description": "A2A JSON-RPC 2.0 endpoint"
    },
    {
      "name": "meta",
      "description": "System status and health"
    }
  ],
  "paths": {
    "/api/agents": {
      "get": {
        "tags": [
          "agents"
        ],
        "summary": "List public agents",
        "description": "Returns agents ranked by trust score descending.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "minScore",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agents": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AgentSummary"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/agents/{owner}/{name}": {
      "get": {
        "tags": [
          "agents"
        ],
        "summary": "Get agent by ID",
        "parameters": [
          {
            "name": "owner",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Agent"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/agents/{owner}/{name}/reputation": {
      "get": {
        "tags": [
          "reputation"
        ],
        "summary": "Get reputation breakdown",
        "parameters": [
          {
            "name": "owner",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Reputation"
                }
              }
            }
          }
        }
      }
    },
    "/api/agents/{owner}/{name}/reputation/history": {
      "get": {
        "tags": [
          "reputation"
        ],
        "summary": "Daily probe history",
        "parameters": [
          {
            "name": "owner",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "maximum": 90
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "agentId": {
                      "type": "string"
                    },
                    "days": {
                      "type": "integer"
                    },
                    "history": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "date": {
                            "type": "string",
                            "format": "date"
                          },
                          "total_probes": {
                            "type": "integer"
                          },
                          "successful_probes": {
                            "type": "integer"
                          },
                          "uptime": {
                            "type": "number"
                          },
                          "avg_latency_ms": {
                            "type": "number"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/agents/claim": {
      "post": {
        "tags": [
          "agents"
        ],
        "summary": "Claim an unclaimed agent",
        "description": "Two-step flow. Step 1: send `{agentId}` to get a token. Step 2: after placing the token, send `{agentId, method}` to confirm.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "agentId": {
                    "type": "string",
                    "example": "opspawn/ai-agent"
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "well-known",
                      "dns-txt"
                    ],
                    "description": "Only required in Step 2"
                  }
                },
                "required": [
                  "agentId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Step 1: verification token. Step 2: claim confirmed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "claimToken": {
                      "type": "string"
                    },
                    "verificationMethods": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "tags": [
          "search"
        ],
        "summary": "Semantic + lexical agent search",
        "description": "Uses Workers AI embeddings + Cloudflare Vectorize. Falls back to LIKE search if Vectorize unavailable.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 10,
              "maximum": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AgentSummary"
                      }
                    },
                    "query": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/attestations": {
      "post": {
        "tags": [
          "attestations"
        ],
        "summary": "Submit a signed peer attestation",
        "security": [
          {
            "bearerToken": []
          },
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AttestationInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Attestation recorded"
          },
          "400": {
            "description": "Invalid signature or payload"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/status": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "System health and aggregate stats",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/me/tokens": {
      "get": {
        "tags": [
          "tokens"
        ],
        "summary": "List your PATs",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "tags": [
          "tokens"
        ],
        "summary": "Create a PAT",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "read",
                        "attest",
                        "publish"
                      ]
                    }
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Token created — shown once",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "scopes": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/me/tokens/{id}": {
      "delete": {
        "tags": [
          "tokens"
        ],
        "summary": "Revoke a PAT",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/a2a": {
      "post": {
        "tags": [
          "a2a"
        ],
        "summary": "A2A JSON-RPC 2.0 endpoint",
        "description": "agentpeering exposes itself as an A2A agent with 5 skills: search, getAgent, listTopAgents, getReputation, submitAttestation.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {
                    "type": "string",
                    "example": "2.0"
                  },
                  "id": {
                    "type": "integer",
                    "example": 1
                  },
                  "method": {
                    "type": "string",
                    "example": "tasks/send"
                  },
                  "params": {
                    "type": "object",
                    "properties": {
                      "message": {
                        "type": "object",
                        "properties": {
                          "role": {
                            "type": "string",
                            "example": "user"
                          },
                          "parts": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "type": {
                                  "type": "string",
                                  "example": "text"
                                },
                                "text": {
                                  "type": "string",
                                  "example": "Find agents for web scraping"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jsonrpc": {
                      "type": "string"
                    },
                    "id": {
                      "type": "integer"
                    },
                    "result": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AgentSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "opspawn/ai-agent"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "verified_at": {
            "type": "integer",
            "description": "Unix ms timestamp or null"
          },
          "card_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Agent": {
        "allOf": [
          {
            "$ref": "#/components/schemas/AgentSummary"
          },
          {
            "type": "object",
            "properties": {
              "card_json": {
                "type": "string",
                "description": "Raw AgentCard JSON"
              },
              "version": {
                "type": "string"
              },
              "auth_schemes": {
                "type": "string"
              },
              "pricing": {
                "type": "string"
              },
              "visibility": {
                "type": "string",
                "enum": [
                  "public",
                  "unlisted",
                  "suspended",
                  "pending"
                ]
              },
              "created_at": {
                "type": "integer"
              },
              "updated_at": {
                "type": "integer"
              },
              "last_seen_at": {
                "type": "integer"
              }
            }
          }
        ]
      },
      "Reputation": {
        "type": "object",
        "properties": {
          "agentId": {
            "type": "string"
          },
          "score": {
            "type": "integer"
          },
          "uptime_30d": {
            "type": "number"
          },
          "p50_latency_ms": {
            "type": "number"
          },
          "p95_latency_ms": {
            "type": "number"
          },
          "attestations_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "integer"
          },
          "components": {
            "type": "object",
            "properties": {
              "uptime": {
                "$ref": "#/components/schemas/ScoreComponent"
              },
              "latency": {
                "$ref": "#/components/schemas/ScoreComponent"
              },
              "attestations": {
                "$ref": "#/components/schemas/ScoreComponent"
              },
              "age": {
                "$ref": "#/components/schemas/ScoreComponent"
              }
            }
          }
        }
      },
      "ScoreComponent": {
        "type": "object",
        "properties": {
          "score": {
            "type": "number"
          },
          "weight": {
            "type": "number"
          },
          "contribution": {
            "type": "number"
          }
        }
      },
      "AttestationInput": {
        "type": "object",
        "required": [
          "agent_id",
          "task_hash",
          "outcome",
          "rating",
          "ts",
          "signature",
          "reporter_pubkey"
        ],
        "properties": {
          "agent_id": {
            "type": "string",
            "example": "opspawn/ai-agent"
          },
          "task_hash": {
            "type": "string",
            "description": "SHA-256 of the task description"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "success",
              "fail",
              "partial"
            ]
          },
          "rating": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5
          },
          "ts": {
            "type": "integer",
            "description": "Unix ms timestamp"
          },
          "signature": {
            "type": "string",
            "description": "Hex-encoded ed25519 signature"
          },
          "reporter_pubkey": {
            "type": "string",
            "description": "Hex-encoded ed25519 public key"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "StatusResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "total_agents": {
            "type": "integer"
          },
          "public_agents": {
            "type": "integer"
          },
          "verified_agents": {
            "type": "integer"
          },
          "agents_with_score": {
            "type": "integer"
          },
          "avg_score": {
            "type": "number"
          },
          "probes_last_hour": {
            "type": "integer"
          },
          "last_probe_at": {
            "type": "integer"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "Personal Access Token (ap_...)"
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "session",
        "description": "Session cookie from GitHub OAuth"
      }
    }
  }
}