Seven steps from creating a TokenRoc API key to reviewing request usage
  1. Create an API key. Store it securely.
  2. Set the base URL. Use https://api.tokenroc.com/v1.
  3. Choose a model. Copy a current ID from Model Square.
  4. Set environment variables. Set TOKENROC_API_KEY and TOKENROC_MODEL.
  5. Send the request. Use Python or curl on your server.
  6. Read the response. Check the message, finish reason and token counts.
  7. Review usage. Check Usage Logs and the dashboard.

Prerequisites

Before you start, make sure you have:

  • A TokenRoc account. You can register in the console if you do not have one.
  • Python 3 and the ability to install packages with pip.
  • A terminal where you can set environment variables.
  • A server-side place to run the code. Never put an API key in browser or mobile client code, where anyone can read it.

Step 1: Create an API key

Sign in to the console and open the API Keys page. Create an API key there and copy it immediately into a secret store or an environment variable.

Create a separate API key for each environment, such as local development, staging, and production. Separate API keys can be revoked independently, so a leaked development API key does not force you to rotate production.

Treat the API key like a password. Do not commit it to Git, paste it into a support ticket, or send it through a contact form. If a API key is exposed, revoke it in the console and create a replacement.

Step 2: Point your client at the TokenRoc base URL

All API requests go to the TokenRoc gateway:

Base URLHTTPS
https://api.tokenroc.com/v1

Because the API is OpenAI-compatible, most existing clients need only this base URL and your TokenRoc API key. The request and response shapes stay the same. The endpoints used in this guide are:

MethodEndpointPurpose
GET/v1/modelsList models available to the current API key.
POST/v1/chat/completionsCreate a standard or streaming chat completion.

A /v1/responses endpoint is also available where the model supports the Responses-compatible request format. The API quickstart lists the current endpoint reference.

Step 3: Choose a current model identifier

A request must name the model you want to run. Model availability changes over time, so do not copy an identifier out of a tutorial and hard-code it, including this one.

Instead, take the exact identifier from a live source:

  • Open the Model Square in the console and copy the identifier shown there, along with its current input and output rates.
  • Or call GET /v1/models with your API key to list what that API key can reach.
terminalGET /v1/models
curl https://api.tokenroc.com/v1/models \
  -H "Authorization: Bearer $TOKENROC_API_KEY"

The rest of this guide reads the identifier from an environment variable called TOKENROC_MODEL, so you can change models without editing code.

Step 4: Set your environment variables

Keep both the API key and the model identifier out of your source files. Set them in your shell, your process manager, or your deployment secret store.

terminalbash / zsh
export TOKENROC_API_KEY="your-api-key"
export TOKENROC_MODEL="paste-an-identifier-from-the-catalog"
terminalPowerShell
$env:TOKENROC_API_KEY = "your-api-key"
$env:TOKENROC_MODEL = "paste-an-identifier-from-the-catalog"

Step 5: Send the request from Python

Install the OpenAI Python SDK, which speaks the same protocol TokenRoc exposes:

terminalpip
pip install openai

Then create the client with your TokenRoc API key and base URL, and send a chat completion. Only those two arguments are TokenRoc-specific; everything else is the standard OpenAI-compatible call.

app.pyPython
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TOKENROC_API_KEY"],
    base_url="https://api.tokenroc.com/v1",
)

response = client.chat.completions.create(
    model=os.environ["TOKENROC_MODEL"],
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Say hello in one sentence."},
    ],
)

print(response.choices[0].message.content)

If you prefer to see the raw HTTP call, the same request with cURL looks like this:

terminalPOST /v1/chat/completions
curl https://api.tokenroc.com/v1/chat/completions \
  -H "Authorization: Bearer $TOKENROC_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"model\": \"$TOKENROC_MODEL\",
    \"messages\": [
      {\"role\": \"user\", \"content\": \"Say hello in one sentence.\"}
    ]
  }"

Authentication uses an API key in the Authorization header, and the body is JSON, so the request needs Content-Type: application/json.

Step 6: Read the response

A successful chat completion returns a JSON object with the generated message and a token accounting summary:

responseapplication/json
{
  "id": "...",
  "object": "chat.completion",
  "created": 0,
  "model": "...",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "..."},
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0
  }
}

The fields you will use most often are:

  • choices[0].message.content - the generated text.
  • choices[0].finish_reason - why generation stopped. Check this before treating output as complete.
  • usage.prompt_tokens, usage.completion_tokens, and usage.total_tokens - the token counts for that call.

In Python, read them from the response object directly:

app.pyPython
print(response.choices[0].message.content)
print(response.choices[0].finish_reason)
print(response.usage.total_tokens)

Step 7: Review usage

Every call reports its own token counts in usage, which is a direct way to measure a single request while you are developing.

For the account-level view, use the console:

  • Usage logs record individual requests, so you can confirm a call arrived and see what it consumed.
  • The dashboard summarises activity across your account.
  • The Model Square shows the current input and output rates for each model, which you need to turn token counts into cost.

Check usage logs early. It is much easier to notice a retry loop or an oversized prompt on the first day than after it has run for a week.

Common errors

Most first-request failures fall into a small number of HTTP responses:

StatusMeaningWhat to check
401Authentication failedConfirm the API key is present, active, and copied without extra spaces or a trailing newline.
403Access or balance rejectedCheck wallet balance, API key permissions, and whether the API key may use that model.
429Rate or quota limitReduce concurrency, apply backoff, or review API key spending limits.
503model_not_foundDo not retry. Check the exact model ID in Model Square.
Other 5xxTemporary server failureRetry with backoff, max 3 times. Read the Errors page for exceptions.
An error about the model usually means the identifier is wrong. Re-copy it from the Model Square or list it with GET /v1/models, rather than guessing a name. Identifiers are exact strings, not display names.

If a request fails before it reaches the API at all, confirm that the base URL is https://api.tokenroc.com/v1 and that your SDK is not still pointing at another service endpoint.

See the Errors page for the complete retry rules, including exceptions.

TokenRoc API error reference for HTTP 401, 403, 429 and 5xx responses

Next steps

Once a single request works end to end:

  • Read the API quickstart for the full endpoint reference and cURL examples.
  • Compare current rates in the Model Square before you commit to a model in production.
  • Create environment-specific API keys on the API Keys page and revoke anything unused.
  • Use the retry rules for 429 and other 5xx responses, excluding model_not_found and parameter errors, and log finish_reason so truncated responses are visible.
  • Check the status page when behaviour changes unexpectedly.

Have a question about an integration? Contact TokenRoc and include the endpoint involved and any non-sensitive error details.