{"openapi":"3.0.3","info":{"title":"Sotro API","version":"1.0.0","description":"Agent-first API and Model Context Protocol (MCP) server for Sotro.\n\n## Quick Start for Agents\n1. Discover capabilities at `GET /.well-known/agent.json` or `GET /api/v1/agent/manifest`.\n2. Create a workspace and `pvk_` org API key in one call via `POST /api/v1/agent/signup`.\n3. Fund your prepaid token wallet via `POST /api/v1/agent/billing/quote` and `POST /api/v1/agent/billing/checkout` (ACH, card, wire, or invoice).\n4. Call REST endpoints with `Authorization: Bearer <token>` or `X-API-Key: <token>`, or connect MCP at `POST /mcp` (Streamable HTTP).\n\n## Authentication\nSend a `pvk_` org API key or `pvt_` member token in either:\n- `Authorization: Bearer <token>`\n- `X-API-Key: <token>`\n\nOptionally scope multi-org member credentials with `X-Org-Id: <orgUuid>`.\n\n## Consistent JSON Errors\nEvery API and MCP error returns `application/json` with the `ErrorResponse` schema:\n`{ \"error\": { \"code\": \"ERR_*\", \"message\": \"...\", \"details\": {} }, \"message\": \"...\" }`.\n","contact":{"name":"Sotro Developers","email":"hello@sotroai.com","url":"https://sotroai.com/developers"}},"servers":[{"url":"https://app.sotroai.com","description":"Production"},{"url":"http://localhost:3000","description":"Local development"}],"tags":[{"name":"Discovery","description":"Machine-readable agent manifests, OpenAPI specs, and health probes"},{"name":"Agent Signup & Access","description":"One-shot agent onboarding, identity status, and API key lifecycle"},{"name":"Payment & Wallet","description":"Prepaid token wallet balance, quotes, Stripe Checkout (ACH/card), wire/invoice instructions, and ledger"},{"name":"Workspace","description":"Workspace creation, member identity, and organization API keys"},{"name":"Decisions & Auto-Continue","description":"Calibrated decisions API and external coding-agent auto-continue"},{"name":"Context & Provenance","description":"Organizational knowledge queries and source provenance"},{"name":"MCP","description":"Streamable HTTP Model Context Protocol server and OAuth discovery"}],"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"pvk_ or pvt_ token","description":"Org API key (`pvk_...`) or member token (`pvt_...`)."},"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"Org API key (`pvk_...`) or member token (`pvt_...`)."}},"schemas":{"ErrorResponse":{"type":"object","required":["error","message"],"properties":{"error":{"type":"object","required":["code","message"],"properties":{"code":{"type":"string","example":"ERR_VALIDATION"},"message":{"type":"string","example":"Missing required field: name"},"details":{"type":"object","additionalProperties":true}}},"message":{"type":"string","example":"Missing required field: name"}}},"AgentManifest":{"type":"object","required":["name","version","baseUrl","signup","auth","payment","mcp","openapi","errors"],"properties":{"name":{"type":"string","example":"Sotro"},"version":{"type":"string","example":"1.0.0"},"baseUrl":{"type":"string","format":"uri"},"signup":{"type":"object","properties":{"endpoint":{"type":"string","example":"/api/v1/agent/signup"},"method":{"type":"string","example":"POST"},"mode":{"type":"string","enum":["open","invite_only"]},"waitlistUrl":{"type":"string","format":"uri"}}},"auth":{"type":"object","properties":{"schemes":{"type":"array","items":{"type":"string"}},"headers":{"type":"array","items":{"type":"string"}}}},"payment":{"type":"object","properties":{"available":{"type":"boolean"},"currency":{"type":"string","example":"usd"},"methods":{"type":"array","items":{"type":"string","enum":["ach","wire","invoice","card"]}},"minTopUpCents":{"type":"integer","example":50000}}},"mcp":{"type":"object","properties":{"endpoint":{"type":"string","example":"/mcp"},"url":{"type":"string","format":"uri"},"transport":{"type":"string","example":"streamable-http"}}},"openapi":{"type":"object","properties":{"json":{"type":"string","format":"uri"},"yaml":{"type":"string","format":"uri"},"docs":{"type":"string","format":"uri"}}},"errors":{"type":"object","properties":{"contentType":{"type":"string","example":"application/json"},"guaranteedValidJson":{"type":"boolean","example":true}}}}},"AgentSignupRequest":{"type":"object","required":["name","email"],"properties":{"name":{"type":"string","description":"Workspace or organization name","example":"Acme Engineering"},"email":{"type":"string","format":"email","description":"Founding owner email (alias adminEmail also accepted)","example":"agent@acme.com"},"agentName":{"type":"string","description":"Friendly label for the default org API key","example":"acme-ops-agent"},"keyName":{"type":"string","description":"Explicit name for the initial pvk_ API key"},"keyRole":{"type":"string","enum":["admin","member"],"default":"admin"},"initialTopUpCents":{"type":"integer","minimum":50000,"description":"Optional prepaid wallet top-up in USD cents to create a Checkout URL immediately"},"paymentMethod":{"type":"string","enum":["ach","card","wire","invoice"],"default":"ach"},"successUrl":{"type":"string","format":"uri"},"cancelUrl":{"type":"string","format":"uri"}}},"WalletSummary":{"type":"object","properties":{"orgId":{"type":"string","format":"uuid"},"balanceMicroUsd":{"type":"integer"},"balanceUsd":{"type":"number"},"hardCutoffMicroUsd":{"type":"integer"},"clearingFeeBps":{"type":"integer"},"lifetimeFundedMicroUsd":{"type":"integer"},"lifetimeSpentMicroUsd":{"type":"integer"},"lifetimeFeeMicroUsd":{"type":"integer"}}},"TopUpQuoteRequest":{"type":"object","required":["creditCents"],"properties":{"creditCents":{"type":"integer","minimum":50000,"example":50000},"paymentMethod":{"type":"string","enum":["ach","card","wire","invoice"],"default":"ach"},"passThroughCardFee":{"type":"boolean","default":true}}},"TopUpQuote":{"type":"object","properties":{"paymentMethod":{"type":"string"},"creditCents":{"type":"integer"},"creditMicroUsd":{"type":"integer"},"processingFeeCents":{"type":"integer"},"totalChargeCents":{"type":"integer"},"estimatedProcessorFeeCents":{"type":"integer"},"tier":{"type":"string","enum":["self_serve","enterprise"]}}},"CheckoutRequest":{"type":"object","required":["creditCents"],"properties":{"creditCents":{"type":"integer","minimum":50000,"example":50000},"paymentMethod":{"type":"string","enum":["ach","card","wire","invoice"],"default":"ach"},"successUrl":{"type":"string","format":"uri"},"cancelUrl":{"type":"string","format":"uri"}}},"ApiKeyCreateRequest":{"type":"object","required":["name"],"properties":{"name":{"type":"string","example":"production-agent"},"role":{"type":"string","enum":["admin","member"],"default":"member"},"scopeId":{"type":"integer","nullable":true}}},"ApiKeyMeta":{"type":"object","properties":{"id":{"type":"integer"},"tenantId":{"type":"string"},"name":{"type":"string"},"role":{"type":"string","enum":["admin","member"]},"scopeId":{"type":"integer","nullable":true},"createdBy":{"type":"string","nullable":true},"lastUsedAt":{"type":"string","format":"date-time","nullable":true},"revoked":{"type":"boolean"}}},"DecideRequest":{"type":"object","required":["state","questions"],"properties":{"state":{"type":"object","additionalProperties":true},"questions":{"type":"array","items":{"type":"object","additionalProperties":true}},"model":{"type":"string"}}}},"responses":{"BadRequest":{"description":"Validation or malformed JSON error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"Missing or invalid credential","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"PaymentRequired":{"description":"Prepaid wallet balance exhausted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"Insufficient permissions or invite-only signup gate","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"NotFound":{"description":"Resource or route not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/.well-known/agent.json":{"get":{"tags":["Discovery"],"summary":"Machine-readable agent bootstrap manifest","description":"Zero-auth discovery endpoint describing signup, auth schemes, prepaid payment rails, MCP endpoint, OpenAPI URLs, SDK, and error contract.","responses":{"200":{"description":"Agent manifest","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentManifest"}}}}}}},"/.well-known/ai-context.json":{"get":{"tags":["Discovery"],"summary":"Context layer and platform capability manifest","responses":{"200":{"description":"Capability manifest","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/openapi.json":{"get":{"tags":["Discovery"],"summary":"OpenAPI 3.0.3 specification (JSON)","responses":{"200":{"description":"OpenAPI JSON document","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/openapi.yaml":{"get":{"tags":["Discovery"],"summary":"OpenAPI 3.0.3 specification (YAML)","responses":{"200":{"description":"OpenAPI YAML document","content":{"application/yaml":{"schema":{"type":"string"}}}}}}},"/api/health":{"get":{"tags":["Discovery"],"summary":"API liveness check","responses":{"200":{"description":"Server healthy","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","example":"ok"},"uptime":{"type":"number"},"timestamp":{"type":"string","format":"date-time"}}}}}}}}},"/api/v1/agent/manifest":{"get":{"tags":["Discovery","Agent Signup & Access"],"summary":"Agent bootstrap manifest","responses":{"200":{"description":"Wrapped agent manifest","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/AgentManifest"}}}}}}}}},"/api/v1/agent/signup":{"post":{"tags":["Agent Signup & Access"],"summary":"One-shot agent workspace signup","description":"Creates a workspace, founding owner, and `pvk_` org API key in one request. Optionally initializes a prepaid wallet Stripe Checkout or wire top-up.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AgentSignupRequest"}}}},"responses":{"201":{"description":"Workspace and credentials provisioned","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"org":{"type":"object"},"member":{"type":"object"},"credentials":{"type":"object","properties":{"apiKey":{"type":"string","nullable":true},"memberToken":{"type":"string"}}},"wallet":{"$ref":"#/components/schemas/WalletSummary"},"payment":{"type":"object","nullable":true},"mcp":{"type":"object"},"nextSteps":{"type":"array","items":{"type":"string"}}}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/agent/status":{"get":{"tags":["Agent Signup & Access"],"summary":"Inspect authenticated agent identity, wallet balance, and MCP config","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Authenticated status","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/agent/keys":{"get":{"tags":["Agent Signup & Access"],"summary":"List workspace API keys (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"responses":{"200":{"description":"API keys list","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/ApiKeyMeta"}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}},"post":{"tags":["Agent Signup & Access"],"summary":"Create a scoped or admin pvk_ API key (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiKeyCreateRequest"}}}},"responses":{"201":{"description":"Created API key (plaintext token shown once)","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"key":{"$ref":"#/components/schemas/ApiKeyMeta"},"token":{"type":"string"}}}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/agent/keys/{id}":{"delete":{"tags":["Agent Signup & Access"],"summary":"Revoke a workspace API key (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Key revoked","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/ApiKeyMeta"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/api/v1/agent/billing":{"get":{"tags":["Payment & Wallet"],"summary":"Read prepaid token wallet balance, policy, tiers, and billing preview (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Wallet and billing overview","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/agent/billing/quote":{"post":{"tags":["Payment & Wallet"],"summary":"Quote a prepaid wallet top-up (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TopUpQuoteRequest"}}}},"responses":{"200":{"description":"Deterministic top-up quote","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/TopUpQuote"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/agent/billing/checkout":{"post":{"tags":["Payment & Wallet"],"summary":"Create a Stripe Checkout session (ACH/card) or wire/invoice instructions (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CheckoutRequest"}}}},"responses":{"201":{"description":"Checkout session URL or wire instructions","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object"}}}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/agent/billing/ledger":{"get":{"tags":["Payment & Wallet"],"summary":"Read prepaid token wallet ledger entries (admin)","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"parameters":[{"name":"limit","in":"query","schema":{"type":"integer","default":50,"maximum":200}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"Paginated ledger entries","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"type":"object"}}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/workspace/orgs":{"post":{"tags":["Workspace"],"summary":"Create a workspace and founding owner","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["name","adminEmail"],"properties":{"name":{"type":"string"},"adminEmail":{"type":"string","format":"email"}}}}}},"responses":{"201":{"description":"Workspace created","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/api/v1/workspace/me":{"get":{"tags":["Workspace"],"summary":"Current workspace member identity and accessible organizations","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Member identity","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/decide":{"post":{"tags":["Decisions & Auto-Continue"],"summary":"Ask calibrated typed decision questions","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/DecideRequest"}}}},"responses":{"200":{"description":"Calibrated answers","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"402":{"$ref":"#/components/responses/PaymentRequired"}}}},"/api/v1/agent-continue/platforms":{"get":{"tags":["Decisions & Auto-Continue"],"summary":"List supported external agent platforms and setup snippets","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"responses":{"200":{"description":"Platform setup guide","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/agent-continue/evaluate":{"post":{"tags":["Decisions & Auto-Continue"],"summary":"Classify an external agent response and auto-continue","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["agentResponse"],"properties":{"agentResponse":{"type":"string"},"goal":{"type":"string"},"platform":{"type":"string"}}}}}},"responses":{"200":{"description":"Classification and routing decision","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/v1/context/query":{"get":{"tags":["Context & Provenance"],"summary":"Search organizational knowledge with source provenance","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"parameters":[{"name":"q","in":"query","required":true,"schema":{"type":"string"}},{"name":"sources","in":"query","schema":{"type":"string"}},{"name":"limit","in":"query","schema":{"type":"integer","maximum":50}}],"responses":{"200":{"description":"Ranked context results with provenance","content":{"application/json":{"schema":{"type":"object"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/mcp":{"get":{"tags":["MCP"],"summary":"MCP server discovery metadata","description":"Returns Streamable HTTP metadata and auth pointers. Requests with `Accept: text/event-stream` return `405` JSON because Streamable HTTP answers on `POST /mcp`.","responses":{"200":{"description":"MCP server metadata","content":{"application/json":{"schema":{"type":"object"}}}},"405":{"description":"SSE stream not used on GET; use POST /mcp","content":{"application/json":{"schema":{"type":"object"}}}}}},"post":{"tags":["MCP"],"summary":"Streamable HTTP JSON-RPC 2.0 MCP endpoint","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["jsonrpc","method"],"properties":{"jsonrpc":{"type":"string","example":"2.0"},"id":{"oneOf":[{"type":"string"},{"type":"integer"}]},"method":{"type":"string","example":"initialize"},"params":{"type":"object"}}}}}},"responses":{"200":{"description":"JSON-RPC 2.0 response","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}},"/.well-known/oauth-protected-resource/mcp":{"get":{"tags":["MCP","Discovery"],"summary":"RFC 9728 OAuth protected resource metadata for MCP","responses":{"200":{"description":"Protected resource metadata (when WorkOS AuthKit OAuth is enabled)","content":{"application/json":{"schema":{"type":"object"}}}},"404":{"$ref":"#/components/responses/NotFound"}}}}}}