Skip to main content

Documentation Index

Fetch the complete documentation index at: https://spendguard.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Endpoint

POST /v1/policies
Authentication: Required (X-API-Key header)

Request Body

FieldTypeRequiredDescription
policy_idstringNoCustom policy ID. If provided and already exists, creates a new version. If omitted, auto-generated.
namestringYesHuman-readable name for the policy
descriptionstringNoWhat this policy is for
rulesarrayYesList of rule objects (minimum 1)
metadataobjectNoOptional key-value metadata

Rule Object

FieldTypeRequiredDescription
rule_idstringYesUnique identifier within the policy (e.g., “r1”)
rule_typestringYesOne of: max_amount, refund_age_limit, blocked_categories, vendor_allowlist, blocked_payment_rails, discount_cap, geography_block, time_restriction, duplicate_guard, escalate_if
descriptionstringNoHuman-readable description
parametersobjectYesRule-specific parameters (see Rule Types)

Example Request

curl -X POST https://spendguardapi.com/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $SPENDGUARD_API_KEY" \
  -d '{
    "policy_id": "my_refund_policy",
    "name": "My Refund Policy",
    "description": "Controls AI agent refund authorization",
    "rules": [
      {
        "rule_id": "r1",
        "rule_type": "max_amount",
        "description": "Block refunds over $500",
        "parameters": { "limit": 500, "currency": "USD" }
      },
      {
        "rule_id": "r2",
        "rule_type": "escalate_if",
        "description": "Escalate refunds over $200",
        "parameters": { "amount_above": 200, "action_types": ["refund"] }
      }
    ]
  }'

Response — 201 Created

{
  "policy_id": "my_refund_policy",
  "name": "My Refund Policy",
  "description": "Controls AI agent refund authorization",
  "version": 1,
  "rules": [
    {
      "rule_id": "r1",
      "rule_type": "max_amount",
      "description": "Block refunds over $500",
      "parameters": { "limit": 500, "currency": "USD" }
    },
    {
      "rule_id": "r2",
      "rule_type": "escalate_if",
      "description": "Escalate refunds over $200",
      "parameters": { "amount_above": 200, "action_types": ["refund"] }
    }
  ],
  "created_at": "2026-04-03T12:00:00Z",
  "updated_at": "2026-04-03T12:00:00Z",
  "metadata": null
}

Versioning

If you POST with a policy_id that already exists, SpendGuard creates version 2 (or 3, 4, etc.) instead of overwriting. The previous version is preserved permanently.

Error Responses

StatusCodeWhen
401unauthorizedMissing or invalid API key
422validation_errorInvalid rule_type, missing required fields, or empty rules array
500internal_errorServer error