Developer API

Drop-in OpenAI replacement

The StudyAIMastery API speaks OpenAI’s wire protocol. Point your existing client at https://studyaimastery.com/api/v1 and use a StudyAIMastery API key. 11 text models, 8 image models, one bill.

11
Text models
8
Image models
Bearer
Auth

Getting started

  1. Upgrade to Master tier ($197/mo).
  2. Create a key at /settings/api-keys. Plaintext is shown once — save it.
  3. Plug the key into any OpenAI SDK as a bearer token.

Authentication

Pass your key in the Authorization header. Keys start with sk-sam-.

Authorization: Bearer sk-sam-xxxxxxxxxxxxxxxxxxxxxxxx

Chat completions — curl

curl https://studyaimastery.com/api/v1/chat/completions \
  -H "Authorization: Bearer $STUDYAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4-mini",
    "messages": [
      {"role": "user", "content": "Say hi in one sentence."}
    ]
  }'

Chat completions — OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
    base_url="https://studyaimastery.com/api/v1",
    api_key="sk-sam-...",
)

resp = client.chat.completions.create(
    model="anthropic/claude-opus-4.7",
    messages=[{"role": "user", "content": "Two sentences on Goedel."}],
)
print(resp.choices[0].message.content)

Tools / function calling

Pass tools and tool_choice exactly as you would to OpenAI. Assistant responses carry tool_calls with arguments as a JSON string; send back a {"role":"tool","tool_call_id":"..."} message with the function result to continue.

resp = client.chat.completions.create(
    model="openai/gpt-5.4",
    messages=[{"role": "user", "content": "What's the weather in NYC?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        },
    }],
)
tool_call = resp.choices[0].message.tool_calls[0]
# tool_call.function.name -> "get_weather"
# tool_call.function.arguments -> '{"city": "NYC"}'

Streaming

Set stream=true for Server-Sent Events in OpenAI’s format. Every SDK that supports streaming against api.openai.com works out of the box.

stream = client.chat.completions.create(
    model="openai/gpt-5.4",
    messages=[{"role": "user", "content": "Explain entropy."}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content or ""
    print(delta, end="", flush=True)

Embeddings

POST /api/v1/embeddings with model + input. Routes through OpenAI for text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002.

resp = client.embeddings.create(
    model="text-embedding-3-small",
    input=["hello world", "another doc"],
)
print(len(resp.data[0].embedding))  # 1536

Max 100 inputs per request. Each input capped at 100k chars. Returns OpenAI’s response shape with our usage.cost_usd overlaid.

Image generation

curl https://studyaimastery.com/api/v1/images/generations \
  -H "Authorization: Bearer $STUDYAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "fal-ai/flux-pro/v1.1-ultra",
    "prompt": "A retrofuturist library, warm sunlight, cinematic"
  }'

Response has an OpenAI-compatible data[0].url. Some providers (notably Gemini) return a data: URI; in that case we also populate b64_json.

Models

Text

Image

Or discover programmatically: GET /api/v1/models

Limits

  • 1,000 chat completions / day per user, reset at 00:00 UTC.
  • 200 image generations / day.
  • 10 active API keys per user (create/revoke from settings).
  • 40,000-char message cap per message in a chat completion request.

Errors

Error shape matches OpenAI — {"error": {"message": "...", "type": "..."}}.

  • 401 invalid_api_key
  • 403 insufficient_tier
  • 400 invalid_request_error
  • 429 rate_limit_exceeded
  • 502 upstream_error
Not yet supported: logprobs, vision inputs, video. Roadmap-tracked — email lamont@studyaimastery.com with what you need first.
Evaluating us against OpenRouter, Replicate, or other API providers? Honest comparisons.