{
  "openapi": "3.0.3",
  "info": {
    "title": "SocialDB Agent Commerce API",
    "version": "1.0.0",
    "description": "Discover creators and book paid deals on a brand's behalf. Bookings are funded from the brand's pre-funded SocialDB wallet into escrow (released on approval), bounded by the agent key's per-transaction and monthly caps. Authenticate with an agent key minted at https://socialdb.xyz/settings#agents, sent as 'Authorization: Bearer <key>'."
  },
  "servers": [{ "url": "https://socialdb.xyz" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/api/agent": {
      "get": {
        "operationId": "agentGet",
        "summary": "search / quote / deal / wallet (via ?action=)",
        "parameters": [
          { "name": "action", "in": "query", "required": true, "schema": { "type": "string", "enum": ["search", "quote", "deal", "wallet"] } },
          { "name": "q", "in": "query", "schema": { "type": "string" }, "description": "search: natural-language query, e.g. 'fitness TikTokers under 100k in the US'" },
          { "name": "platform", "in": "query", "schema": { "type": "string" } },
          { "name": "niche", "in": "query", "schema": { "type": "string" } },
          { "name": "country", "in": "query", "schema": { "type": "string" } },
          { "name": "min_followers", "in": "query", "schema": { "type": "integer" } },
          { "name": "max_followers", "in": "query", "schema": { "type": "integer" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20 } },
          { "name": "creator_id", "in": "query", "schema": { "type": "integer" }, "description": "quote" },
          { "name": "type", "in": "query", "schema": { "type": "string", "enum": ["sponsor", "ugc", "podcast"] } },
          { "name": "amount_usd", "in": "query", "schema": { "type": "number" } },
          { "name": "deal_id", "in": "query", "schema": { "type": "integer" }, "description": "deal" }
        ],
        "responses": { "200": { "description": "OK" }, "401": { "description": "missing/invalid agent key" }, "429": { "description": "rate limited" } }
      },
      "post": {
        "operationId": "agentPost",
        "summary": "quote / book / top_up (JSON body with 'action')",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object",
            "required": ["action"],
            "properties": {
              "action": { "type": "string", "enum": ["quote", "book", "top_up"] },
              "creator_id": { "type": "integer" },
              "type": { "type": "string", "enum": ["sponsor", "ugc", "podcast"], "default": "sponsor" },
              "amount_usd": { "type": "number", "description": "Omit on book/quote to use the suggested rate." },
              "brief": { "type": "string", "description": "book: what you want (deal terms)." },
              "deliverables": { "type": "string" },
              "idempotency_key": { "type": "string", "description": "book: makes retries safe (returns the original booking)." }
            }
          } } }
        },
        "responses": {
          "200": { "description": "booked/quoted" },
          "401": { "description": "missing/invalid agent key" },
          "402": { "description": "insufficient wallet balance or over a cap" },
          "409": { "description": "creator does not auto-accept (not instantly bookable)" },
          "429": { "description": "rate limited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "A SocialDB agent key (sdb_ak_…) from /settings#agents." }
    }
  }
}
