API Keys, Spend Limits & Access

Every client request—including Chat (/) and MCP (/mcp)—authenticates with an API Key (/api-keys). Keys isolate model visibility, rate limits, spend budgets, and platform tool privileges per client or team.

Create API Key sheet showing model allowlist selection

Two independent API Key paths for platform tools: Transparent Injection vs Explicit MCP

Prerequisites

  • At least one enabled Model Route: Prepare the Model IDs you want the key to access.

Steps

  1. Create and scope an API key

    Open Setup → API Keys → Create key (or click an existing key to edit at /api-keys/[id]):

    • Name & Expiration: Set a descriptive label and optional expiration timestamp.
    • Allowed models: Leave Allow all models checked, or restrict the key to specific logical models. (On Connect clients, a key must allow at least one eligible inference or image route.)
    • RPM limit: Leave blank for unlimited, or enter an integer request limit enforced across a strict 60-second sliding window (one client request = one count, regardless of stream length).
  2. Set and reset Spend limits (spend_limit)

    Optionally assign a positive decimal Spend limit in your configured currency (USD or custom currency). Before accepting inference or MCP work, Stravia checks available budget before applying RPM admission.

    • You can explicitly reset accumulated spend (POST /api/v1/api-keys/{id}/spend/reset) after confirmation.
    • Resetting spend zeroes the key's spend counter without deleting historical billing records, usage charts, or disabling the key.
  3. Separate MCP access from Transparent Injection

    Stravia exposes two independent tool-permission controls on every API key:

    • MCP access (mcp_access_enabled): Allows MCP clients connecting to /mcp to authenticate with this key and call tools/list / tools/call for enabled platform capabilities. Enabling MCP access does not turn on transparent injection.
    • Transparent tool injection (transparent_injection_enabled + transparent_injections[]): When the master switch is on, Stravia exposes a base StraviaRead reader (for upstream-referenced files) plus whichever capabilities you explicitly select:
      • web_search — injects StraviaSearch / web search capability into ordinary inference requests.
      • media_understanding — enables image/document/audio understanding tools when the client's chosen model lacks native support or needs extraction.
      • media_generation — exposes image generation (StraviaGenerateImage / generate).
      • history_recall — lets the model search and read past interactions via stravia://history/ (read-only; never exposed over /mcp).
    History recall shares conversations per API key

    history_recall scopes access by API key principal, not per end user. Any caller sharing the same API key can read prior conversations and tool arguments recorded under that key within log_retention_days.

Verify

Copy the generated key (e.g., sk-stravia-demo-not-a-real-key in documentation examples) and call /v1/models or send a test chat request. Verify the key only lists and invokes its authorized models.

Troubleshooting

  • Client receives 402 / spend limit exceeded or 429 RPM error: Check the key's remaining spend budget or 60-second sliding request rate on /api-keys.
  • Legacy inject_* fields rejected via Admin API: Since v0.7.0, inject_web_search, inject_media_understanding, and inject_media_generation booleans are removed; use transparent_injections: [...] instead.

Next