myaiapi

Documentation

myaiapi is a proxy that lets you use one key to call Anthropic and OpenAI models, with subscription billing and wallet overages. The base URL is https://myaiapi-gateway.ujjwal-e32.workers.dev.

Quickstart

  1. Sign up and verify your email.
  2. Subscribe to a plan or top up your wallet.
  3. Go to /app/keys and create a proxy key (starts with sk-).
  4. Point any Anthropic- or OpenAI-compatible client at the base URL above, using your proxy key.

First request? Try the playground.

Authentication

All proxy requests need a key. Two header forms are accepted:

Authorization: Bearer sk-...      # OpenAI-style
x-api-key: sk-...                # Anthropic-style

Either works on either endpoint — pick whichever your SDK already sends.

Keys are listed and revocable at /app/keys. Revoked keys reject within ~60 seconds (KV cache TTL).

POST /v1/messages

Anthropic-shape endpoint. Accepts the request body Anthropic's Messages API expects.

curl -X POST https://myaiapi-gateway.ujjwal-e32.workers.dev/v1/messages \
  -H "x-api-key: $MYAIAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 256,
    "messages": [{"role":"user","content":"What is the capital of India?"}]
  }'

You can also pass an OpenAI model slug here (e.g. gpt-4o) — the gateway translates the request to OpenAI's chat-completions shape, calls OpenAI, and returns the response in Anthropic format. One client, both providers.

Streaming: set "stream": true; responses are SSE in Anthropic's event format regardless of which provider serves them.

POST /v1/chat/completions

OpenAI-shape endpoint. Accepts the body OpenAI's chat.completions API expects.

curl -X POST https://myaiapi-gateway.ujjwal-e32.workers.dev/v1/chat/completions \
  -H "Authorization: Bearer $MYAIAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role":"user","content":"Hello!"}]
  }'

Pass "model": "claude-sonnet-4-5" and the gateway calls Anthropic + translates the response back to OpenAI format.

Models & pricing

Pricing is in INR (₹), per million tokens. The gateway converts each request's USD upstream cost using the configured FX rate and applies a markup.

Loading…

CLI: Claude Code

Use myaiapi as Claude Code's backend by setting these env vars:

export ANTHROPIC_BASE_URL=https://myaiapi-gateway.ujjwal-e32.workers.dev
export ANTHROPIC_API_KEY=sk-...   # your proxy key
claude

Claude Code calls /v1/messages against the base URL — the gateway routes to Anthropic (or to OpenAI if you set ANTHROPIC_MODEL=gpt-4o).

CLI: OpenAI SDK

Point the official OpenAI SDK at myaiapi by overriding base_url.

# Python
from openai import OpenAI
client = OpenAI(
    base_url="https://myaiapi-gateway.ujjwal-e32.workers.dev/v1",
    api_key="sk-...",
)
r = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role":"user","content":"Hi"}],
)
print(r.choices[0].message.content)
// Node / TypeScript
import OpenAI from "openai";
const client = new OpenAI({
  baseURL: "https://myaiapi-gateway.ujjwal-e32.workers.dev/v1",
  apiKey: process.env.MYAIAPI_KEY,
});
const r = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hi" }],
});
console.log(r.choices[0].message.content);

CLI: Anthropic SDK

# Python
from anthropic import Anthropic
client = Anthropic(
    base_url="https://myaiapi-gateway.ujjwal-e32.workers.dev",
    api_key="sk-...",
)
r = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=256,
    messages=[{"role":"user","content":"Hi"}],
)
print(r.content[0].text)
// Node
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
  baseURL: "https://myaiapi-gateway.ujjwal-e32.workers.dev",
  apiKey: process.env.MYAIAPI_KEY,
});
const r = await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 256,
  messages: [{ role: "user", content: "Hi" }],
});
console.log(r.content[0].text);

CLI: curl & streaming

# Streaming
curl -N -X POST https://myaiapi-gateway.ujjwal-e32.workers.dev/v1/messages \
  -H "x-api-key: $MYAIAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 256,
    "stream": true,
    "messages": [{"role":"user","content":"Tell me a haiku."}]
  }'

The -N flag disables curl's output buffering so SSE chunks print as they arrive.

Billing

Every request is billed in this order:

  1. Active subscription — if the request fits inside the period's included quota, billed to the subscription. No wallet deduction.
  2. Wallet — if no subscription headroom remains, the cost is deducted from your wallet balance.
  3. 402 no_funding — if neither funding source has balance.

See live status at /app/billing. Manage subscriptions and top-ups at /pricing.

Renewal: monthly subscriptions don't auto-charge. You'll get a reminder email 3 days before the period ends; click the link to renew. Wallet credit covers usage after a subscription expires.

Errors

Status Code Meaning
401 no_key / bad_key Missing or invalid proxy key.
402 no_funding No subscription headroom and zero wallet balance.
402 spend_cap_exceeded User-configured spend cap (hourly/daily/weekly) exceeded.
404 unknown_model Model slug not in the registry. See Models.
429 rate_limited Per-key rate limit exceeded. Backoff and retry.
5xx upstream_error Anthropic or OpenAI returned an error. Body is forwarded.

Rate limits

Each proxy key has a sliding-window rate limit enforced by a Durable Object. Default: 60 requests / minute. Contact us if you need more.

Spend caps are separate — they prevent runaway cost regardless of rate. Configure them at /app/settings.

Questions? Email connect@rs.threemates.tech.