{
  "openapi": "3.1.0",
  "info": {
    "title": "SendGuard API",
    "version": "2026-11-14",
    "description": "SendGuard is the pre-send decision layer for AI agents. Its hosted Email Preflight API returns allow, delay, requires_approval or block with reasons. Call POST /v1/preflight/email before each send; your existing sender or workflow must enforce the decision. Send only on allow; hold requires_approval for human review, retry delay after delay_seconds, and do not send on block. SendGuard never sends email. Guardrails for customer-operated or self-hosted email workflows are one use case; the SendGuard API is hosted.\n\nEmail preflight uses non-SMTP recipient signals, sender checks, pattern-based content checks and outbound policy. It does not fact-check content or guarantee delivery. A completed authenticated preflight uses one credit, including when recipient signals are cached or the recipient status is unknown. The separate Email Validation API has different charging rules; consult response billing fields.\n\nAgents without an API key can request one with the device flow (POST /v1/agent/signup, then poll POST /v1/agent/token) after a human approves it.",
    "contact": {
      "email": "support@sendguard.ai",
      "url": "https://sendguard.ai/docs/"
    }
  },
  "servers": [
    {
      "url": "https://api.sendguard.ai"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Preflight"
    },
    {
      "name": "Verification"
    },
    {
      "name": "Agent signup"
    },
    {
      "name": "Billing"
    }
  ],
  "paths": {
    "/v1/preflight/email": {
      "post": {
        "tags": [
          "Preflight"
        ],
        "operationId": "preflightEmail",
        "summary": "Check an outbound email before sending",
        "description": "Requires scope preflight:read. Uses one credit when charged.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreflightRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PreflightResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InsufficientCredits"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/email/verify": {
      "post": {
        "tags": [
          "Verification"
        ],
        "operationId": "verifyEmail",
        "summary": "Verify a recipient address",
        "description": "Requires scope verify:create. Alias of POST /v1/email/decision.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "policy": {
                    "type": "string",
                    "enum": [
                      "default",
                      "strict"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Out of credits.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InsufficientCredits"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agent/signup": {
      "post": {
        "tags": [
          "Agent signup"
        ],
        "operationId": "startAgentSignup",
        "security": [],
        "summary": "Request an API key (RFC 8628 device authorization)",
        "description": "Returns a user_code and verification_url for a human to approve in the dashboard, and a device_code to poll with.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "scopes": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Scope"
                    },
                    "description": "Defaults to preflight:read and verify:create."
                  },
                  "monthly_spend_cap_usd": {
                    "type": "number",
                    "minimum": 0,
                    "description": "Requested monthly cap on purchases made with the key. The approver can change it."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signup started",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "device_code": {
                      "type": "string"
                    },
                    "user_code": {
                      "type": "string",
                      "examples": [
                        "ABCD-EFGH"
                      ]
                    },
                    "verification_url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expires_in": {
                      "type": "integer"
                    },
                    "interval": {
                      "type": "integer",
                      "description": "Minimum seconds between polls."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid scope or cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agent/token": {
      "post": {
        "tags": [
          "Agent signup"
        ],
        "operationId": "pollAgentSignup",
        "security": [],
        "summary": "Poll for the API key",
        "description": "Returns the API key exactly once after approval. Errors follow RFC 8628: authorization_pending, slow_down, access_denied, expired_token.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type",
                  "device_code"
                ],
                "properties": {
                  "grant_type": {
                    "type": "string",
                    "const": "urn:ietf:params:oauth:grant-type:device_code"
                  },
                  "device_code": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string"
                    },
                    "token_type": {
                      "type": "string",
                      "const": "bearer"
                    },
                    "scopes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Scope"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Pending, denied or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/catalog": {
      "get": {
        "tags": [
          "Billing"
        ],
        "operationId": "getPricing",
        "summary": "List plans and top-up packages",
        "responses": {
          "200": {
            "description": "Catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "plans": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "top_ups": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TopUpPackage"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/account": {
      "get": {
        "tags": [
          "Billing"
        ],
        "operationId": "getAccount",
        "summary": "Get plan, balance and auto-recharge settings",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "plan": {
                      "type": "string"
                    },
                    "plan_name": {
                      "type": "string"
                    },
                    "credit_balance": {
                      "type": "integer"
                    },
                    "top_up_credit_balance": {
                      "type": "integer"
                    },
                    "free_credits_remaining": {
                      "type": "integer"
                    },
                    "subscription_credits_remaining": {
                      "type": "integer"
                    },
                    "monthly_credits_included": {
                      "type": "integer"
                    },
                    "monthly_credits_reset_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "total_balance": {
                      "type": "integer"
                    },
                    "stripe_subscription_status": {
                      "type": "string"
                    },
                    "subscription_current_period_end": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "has_managed_subscription": {
                      "type": "boolean"
                    },
                    "can_purchase_topups": {
                      "type": "boolean"
                    },
                    "auto_recharge": {
                      "type": "object"
                    }
                  },
                  "description": "Over MCP (get_account) Stripe customer and subscription IDs are omitted."
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/topups/checkout-link": {
      "post": {
        "tags": [
          "Billing"
        ],
        "operationId": "createTopUpLink",
        "summary": "Create a hosted checkout link for a top-up",
        "description": "Requires a live API key with scope billing:topup. A human opens checkout_url and pays; credits are added when payment completes. Counts toward the key's monthly spend cap.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "package_id"
                ],
                "properties": {
                  "package_id": {
                    "type": "string",
                    "examples": [
                      "pilot"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "checkout_url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "package_id": {
                      "type": "string"
                    },
                    "credits": {
                      "type": "integer"
                    },
                    "price_usd_cents": {
                      "type": "integer"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown package.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still in progress.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Idempotency-Key reused with a different body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/topups/auto-recharge": {
      "post": {
        "tags": [
          "Billing"
        ],
        "operationId": "runAutoRecharge",
        "summary": "Charge the saved card for the owner-configured auto-recharge package",
        "description": "Requires a live API key with scope billing:autorecharge and auto-recharge enabled by the owner. Counts toward the key's monthly spend cap.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    },
                    "credits_added": {
                      "type": "integer"
                    },
                    "total_balance": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "A request with this Idempotency-Key is still in progress.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope (body names required_scope).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/topups/x402/{package_id}": {
      "post": {
        "tags": [
          "Billing"
        ],
        "operationId": "buyTopUpWithX402",
        "summary": "Buy a top-up package with an x402 USDC payment",
        "description": "Only available when the server enables x402 top-ups (currently Base Sepolia testnet, so not in production). Requires a live API key with scope billing:topup and counts toward the key's monthly spend cap. Call once without payment to get the 402 PAYMENT-REQUIRED header (price = package price in USDC), then retry with a PAYMENT-SIGNATURE header. Credits are only added after the payment settles; the PAYMENT-RESPONSE header carries the settlement proof.",
        "parameters": [
          {
            "name": "package_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "pilot",
                "starter",
                "growth"
              ]
            }
          },
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "required": false,
            "description": "Base64 x402 v2 payment payload for the package price.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payment settled and credits added. PAYMENT-RESPONSE header contains the settlement.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "credited"
                    },
                    "package_id": {
                      "type": "string"
                    },
                    "credits": {
                      "type": "integer"
                    },
                    "price_usd_cents": {
                      "type": "integer"
                    },
                    "network": {
                      "type": "string",
                      "examples": [
                        "eip155:84532"
                      ]
                    },
                    "total_balance": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown package.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key. Body includes next_action=start_agent_signup.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Payment required, rejected, or failed to settle. The PAYMENT-REQUIRED header lists the accepted payment (scheme exact, USDC)."
          },
          "403": {
            "description": "live_api_key_required, insufficient_scope (required_scope=billing:topup) or spend_cap_exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "x402 top-ups are not enabled on this server."
          },
          "500": {
            "description": "credit_failed: the payment settled but credits were not added. Body includes transaction; email support@sendguard.ai.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "SendGuard API key (sk_live_... or sk_test_...)."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Optional, up to 255 characters. Retries with the same key and body replay the first response with header Idempotent-Replayed: true.",
        "schema": {
          "type": "string",
          "maxLength": 255
        }
      }
    },
    "schemas": {
      "Scope": {
        "type": "string",
        "enum": [
          "preflight:read",
          "verify:create",
          "billing:topup",
          "billing:autorecharge"
        ]
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "next_action": {
            "type": "string"
          },
          "required_scope": {
            "$ref": "#/components/schemas/Scope"
          },
          "signup_endpoint": {
            "type": "string"
          }
        }
      },
      "DeviceError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_request",
              "authorization_pending",
              "slow_down",
              "access_denied",
              "expired_token"
            ]
          },
          "error_description": {
            "type": "string"
          }
        }
      },
      "InsufficientCredits": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "const": "insufficient_credits"
          },
          "message": {
            "type": "string"
          },
          "next_action": {
            "type": "string",
            "enum": [
              "auto_recharge",
              "create_checkout_link",
              "human_topup"
            ],
            "description": "auto_recharge: call POST /v1/billing/topups/auto-recharge. create_checkout_link: call POST /v1/billing/topups/checkout-link and hand the link to a human. human_topup: ask a human to buy credits at billing_url."
          },
          "can_create_checkout_link": {
            "type": "boolean"
          },
          "can_auto_recharge": {
            "type": "boolean"
          },
          "recommended_top_up_package_id": {
            "type": "string"
          },
          "billing_url": {
            "type": "string",
            "format": "uri"
          },
          "checkout_url": {
            "type": "string",
            "format": "uri"
          },
          "topup_endpoint": {
            "type": "string"
          },
          "pricing_url": {
            "type": "string",
            "format": "uri"
          },
          "plan": {
            "type": "string"
          }
        }
      },
      "TopUpPackage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "credits": {
            "type": "integer"
          },
          "price_usd_cents": {
            "type": "integer"
          },
          "per_check": {
            "type": "string"
          },
          "best_for": {
            "type": "string"
          },
          "recommended": {
            "type": "boolean"
          },
          "purchase_type": {
            "type": "string"
          }
        }
      },
      "ReasonCode": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "PreflightRequest": {
        "type": "object",
        "required": [
          "from",
          "to"
        ],
        "properties": {
          "workspace_id": {
            "type": "string"
          },
          "agent_id": {
            "type": "string"
          },
          "campaign_id": {
            "type": "string"
          },
          "policy": {
            "type": "string",
            "enum": [
              "default",
              "balanced",
              "strict",
              "growth",
              "enterprise",
              "healthcare",
              "recruiting"
            ]
          },
          "from": {
            "type": "object",
            "required": [
              "email"
            ],
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              },
              "domain_age_days": {
                "type": "integer"
              },
              "mailbox_age_days": {
                "type": "integer"
              }
            }
          },
          "to": {
            "type": "object",
            "required": [
              "email"
            ],
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              },
              "name": {
                "type": "string"
              },
              "company": {
                "type": "string"
              },
              "industry": {
                "type": "string"
              },
              "country": {
                "type": "string",
                "description": "ISO 3166-1 alpha-2"
              },
              "source": {
                "type": "string"
              }
            }
          },
          "message": {
            "type": "object",
            "properties": {
              "subject": {
                "type": "string"
              },
              "body": {
                "type": "string"
              }
            }
          },
          "context": {
            "type": "object",
            "properties": {
              "intent": {
                "type": "string"
              },
              "relationship": {
                "type": "string"
              },
              "is_opted_in": {
                "type": "boolean"
              },
              "has_unsubscribed": {
                "type": "boolean"
              },
              "crm_stage": {
                "type": "string"
              },
              "sequence_step": {
                "type": "integer",
                "minimum": 1
              }
            }
          }
        }
      },
      "PreflightResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "decision": {
            "type": "string",
            "enum": [
              "allow",
              "delay",
              "requires_approval",
              "block"
            ]
          },
          "risk_score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "confidence": {
            "type": "number"
          },
          "delay_seconds": {
            "type": "integer"
          },
          "reasons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReasonCode"
            }
          },
          "recommendations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "approval": {
            "type": "object",
            "properties": {
              "queue": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            }
          },
          "suggested_email": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "billing": {
            "type": "object",
            "properties": {
              "charged": {
                "type": "boolean"
              },
              "units": {
                "type": "integer"
              },
              "reason": {
                "type": "string"
              },
              "balance_remaining": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}
