{
  "openapi": "3.1.0",
  "info": {
    "title": "TensorPM API",
    "version": "1.0.0",
    "description": "TensorPM commerce + credit endpoints (proxy) and local A2A endpoint (desktop). The MCP server is described separately at /.well-known/mcp/server-card.json. For end-user pricing rules see /PRICING.md.",
    "contact": {
      "name": "TensorPM Support",
      "email": "support@tensorpm.com",
      "url": "https://tensorpm.com/contact"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://tensorpm.com/en/legal/terms"
    },
    "x-anthropic": {
      "agentReady": true,
      "skill": "https://tensorpm.com/SKILL.md"
    },
    "x-openai": {
      "isConsequential": false
    }
  },
  "servers": [
    {
      "url": "https://api.tensorpm.com",
      "description": "TensorPM Proxy (cloud) — auth, billing, credits, AI proxy"
    },
    {
      "url": "http://localhost:37850",
      "description": "TensorPM Desktop A2A endpoint (local-only, requires desktop app running)"
    }
  ],
  "tags": [
    { "name": "credits", "description": "Credit balance, top-ups, auto-topup settings" },
    { "name": "subscriptions", "description": "Stripe-backed subscription lifecycle" },
    { "name": "acp", "description": "Agentic Commerce Protocol — programmatic catalog and checkout for agents" },
    { "name": "a2a", "description": "Agent-to-Agent JSON-RPC 2.0 (local desktop)" },
    { "name": "discovery", "description": "Well-known agent and MCP discovery resources" }
  ],
  "paths": {
    "/api/credits": {
      "get": {
        "tags": ["credits"],
        "summary": "Get current credit balance and monthly allowance",
        "description": "Returns the authenticated user's credit balance, monthly Pro allowance (if any), and recent usage. Credits never expire on top-up packs; Pro monthly credits reset on the 1st UTC.",
        "security": [{ "bearer": [] }],
        "responses": {
          "200": {
            "description": "Credit summary",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreditSummary" }
              }
            }
          }
        }
      }
    },
    "/api/credits/topup": {
      "post": {
        "tags": ["credits"],
        "summary": "Create a Stripe Checkout session for a one-off credit top-up",
        "description": "Returns a Stripe Checkout URL. Top-up packs: 500k for €1.99, 2M for €5.99. Credits are applied within seconds of webhook fire. Idempotent via credit_topup_sessions.",
        "security": [{ "bearer": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["pack"],
                "properties": {
                  "pack": {
                    "type": "string",
                    "enum": ["500k", "2M"],
                    "description": "Top-up pack size"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stripe Checkout URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "checkoutUrl": { "type": "string", "format": "uri" },
                    "sessionId": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/credits/settings": {
      "patch": {
        "tags": ["credits"],
        "summary": "Update auto top-up settings",
        "description": "Configure opt-in auto top-up. Only available to Pro/Cloud subscribers. Triggered when a credit reservation fails.",
        "security": [{ "bearer": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "autoTopupEnabled": { "type": "boolean" },
                  "autoTopupPack": { "type": "string", "enum": ["500k", "2M"] },
                  "autoTopupMaxPerMonth": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Maximum auto top-up purchases per calendar month"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated settings"
          }
        }
      }
    },
    "/acp/catalog": {
      "get": {
        "tags": ["acp"],
        "summary": "Agentic Commerce Protocol — product catalog",
        "description": "Returns all subscription tiers and top-up packs in ACP-compatible format. Use this to programmatically present TensorPM offers to a user via an AI agent.",
        "responses": {
          "200": {
            "description": "ACP catalog",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AcpCatalog" }
              }
            }
          }
        }
      }
    },
    "/acp/checkouts": {
      "post": {
        "tags": ["acp"],
        "summary": "Create an ACP checkout for a subscription or top-up",
        "description": "Initiates an Agentic Commerce Protocol checkout. Returns a payment URL the agent can hand to the user.",
        "security": [{ "bearer": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["productId"],
                "properties": {
                  "productId": { "type": "string" },
                  "returnUrl": { "type": "string", "format": "uri" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ACP checkout response"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "CreditSummary": {
        "type": "object",
        "properties": {
          "balance": { "type": "integer", "description": "Current credit balance (lifetime + monthly + top-ups)" },
          "monthlyAllowance": { "type": "integer", "description": "Pro monthly allowance (0 for non-Pro)" },
          "monthlyUsed": { "type": "integer" },
          "monthlyResetAt": { "type": "string", "format": "date-time" },
          "tier": { "type": "string", "enum": ["local", "cloud", "pro"] },
          "autoTopupEnabled": { "type": "boolean" }
        }
      },
      "AcpCatalog": {
        "type": "object",
        "properties": {
          "version": { "type": "string" },
          "products": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string" },
                "type": { "type": "string", "enum": ["digital_subscription", "credit_pack"] },
                "name": { "type": "string" },
                "price": { "type": "object" },
                "description": { "type": "string" }
              }
            }
          }
        }
      }
    }
  }
}
