Quickstart

Make your first API call in five minutes — curl, Python, Node.js, or the OpenAI/Anthropic SDKs.

1. Get an API key

  1. Sign in to the portal.
  2. Open a project (or create one under Projects).
  3. Create an API key. The plaintext key is shown once at creation — store it in a secret manager, not in code.

Keys are hierarchical (Organisation → Project → API key) and carry their own model allowlist, IP allowlist, plan, rate limit, and optional spend cap.

2. Your first chat completion

curl https://api.<domain>/v1/chat/completions \
  -H "Authorization: Bearer $TOKENFACTORY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

3. What you get back

{
  "id": "chatcmpl-1",
  "object": "chat.completion",
  "created": 1724680001,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Hello! How can I help?", "refusal": null },
      "finish_reason": "stop",
      "logprobs": null
    }
  ],
  "usage": { "prompt_tokens": 5, "completion_tokens": 9, "total_tokens": 14 },
  "provider_metadata": { "provider": "openai", "actual_model": "gpt-4o-2024-08-06" }
}

Two things to notice:

  • model is the alias you sent, even though the provider's own model id (gpt-4o-2024-08-06) actually served the request. That id is always in provider_metadata.actual_model.
  • provider_metadata is always present on every successful JSON body — you can code against it unconditionally.

4. Point an existing OpenAI integration at the gateway

The only two lines that change are base_url and api_key:

client = OpenAI(
    base_url="https://api.<domain>/v1",
    api_key=os.environ["TOKENFACTORY_API_KEY"],
)

The same is true for TypeScript, Go, and any OpenAI-compatible tool (LangChain, Vercel AI SDK, Cursor, etc.): set the base URL to https://api.<domain>/v1 and use a Token Factory key.

5. Try other modalities

Every modality follows the same pattern — alias in, standard body out:

TaskEndpointGuide
Chat with tools/visionPOST /v1/chat/completionsChat Completions
Streamingstream: true on chatStreaming
EmbeddingsPOST /v1/embeddingsEmbeddings
Image generationPOST /v1/images/generationsImage Generation
Speech to textPOST /v1/audio/transcriptionsTranscriptions
Text to speechPOST /v1/audio/speechText to Speech
RerankingPOST /v1/rerankRerank
Video generationPOST /v1/videos (async)Videos: Create

Common first-call mistakes

SymptomCauseFix
404 model_not_foundA provider-native id was sent (gpt-4o-2024-08-06) or the alias is not on your key's allowlist.Use a curated alias from Models in the portal.
401 invalid_api_keyKey mistyped, revoked, or from another environment.Re-copy the key; check you are on the right deployment.
402 insufficient_fundsThe organisation wallet has no credit.Top up in Billing, then retry.
403 model_not_allowedThe key's model allowlist excludes the alias.Add the alias to the key (Settings → API keys).