API Guide

Fetch rotated API keys for your tenant’s services.

Quickstart

  1. In the app, create a Service (slug e.g. openai) and add your provider keys.
  2. Copy your Client Access Token from Settings.
  3. Call the API to get a key at runtime.
curl -s "https://botinbinary.com/keyrotator/api/next.php?service=openai&token=YOUR_TENANT_CLIENT_TOKEN&mask=1"

Add &mask=1 to mask the key in responses (recommended).

Endpoint

GET https://botinbinary.com/keyrotator/api/next.php

QueryRequiredDescription
serviceYesService slug you defined (e.g. openai).
tokenYes*Tenant client token, or use app_token if per-app tokens are enabled.
app_tokenNoToken of a client app (overrides token), if using per-app tokens.
maskNo1 to mask the key in response. Demo always masks.

Returns 200 JSON with the selected key and meta.

{
  "service": "openai",
  "key_label": "Primary",
  "key": "sk-••••••••••••••••••••••••zzZZ",
  "masked": true,
  "policy": "manual",
  "limits": {"max_daily_requests": 10000},
  "meta": {"key_id": 123, "usage_today": 42}
}

Examples

curl
curl -s "https://botinbinary.com/keyrotator/api/next.php?service=openai&token=YOUR_TENANT_CLIENT_TOKEN&mask=1"
Node (fetch)
const res = await fetch("https://botinbinary.com/keyrotator/api/next.php?service=openai&token=YOUR_TENANT_CLIENT_TOKEN&mask=1");
const data = await res.json();
const apiKey = data.key; // masked if mask=1 (recommended)
Python (requests)
import requests
r = requests.get("https://botinbinary.com/keyrotator/api/next.php", params={"service":"openai","token":"YOUR_TENANT_CLIENT_TOKEN","mask":"1"})
data = r.json()
api_key = data["key"]

Errors

HTTPReasonBody
400Missing params{"error":"missing token or service"}
403Bad token / IP not allowed{"error":"invalid token"}, {"error":"ip not allowed"}
404Unknown service{"error":"unknown service"}
429Daily limit / demo throttle{"error":"service daily limit reached"}
503No active keys{"error":"no active keys"}
500Decrypt error{"error":"key decrypt failed"}

Rotation Policies

  • manual: You rotate when you want.
  • time: Keys expire after N minutes (cron recommended).
  • usage: Balances requests across active keys.

Rate Limits

Each service can define max_daily_requests. Demo traffic is additionally throttled per IP.

Security

  • Keys encrypted (AES-256-GCM) at rest.
  • Tenant isolation; token is per-tenant (or per-app if enabled).
  • Optional IP allowlists per tenant/app.
  • Prefer masked responses (&mask=1).

Webhooks (optional)

Receive notifications like key.delivered, service.limit_reached. Configure in Settings → Webhooks.

Per-app tokens (optional)

Create multiple tokens per tenant application/env, each with its own allowlist & limits. Use app_token=... instead of token.

Try the demo

Use the demo token below (responses are masked):

curl -s "https://botinbinary.com/keyrotator/api/next.php?service=openai&token=52yseGC525k55YpyHUeAdoYrb77WYJ037sPHhQ&mask=1"