GreenTokens

Search

Search models, guides, docs and the FAQ.

GuideBeginner5 min

Switch to GreenTokens in 5 Minutes

Move an app that uses the OpenAI or Anthropic SDK onto GreenTokens by changing the base URL and key, then test it and roll it out safely.

What you'll need

  • An app that already calls the OpenAI or Anthropic API through an official SDK or plain HTTP.
  • A GreenTokens account with some balance. Sign in and top up from the Billing page.

What you'll end up with

Your app sending the same requests to the same models through GreenTokens, with a key you can limit and monitor.

GreenTokens speaks the OpenAI and Anthropic API formats, so switching doesn't mean rewriting your integration. You change two values, the base URL and the API key, and keep everything else: your prompts, your SDK, your parsing code and, usually, your model names.

1. Create an API key

Open the API Keys page in your dashboard and create a key. Name it after the app and environment, for example "support-bot production", so its usage is easy to recognise later.

  • Copy the key straight away. It starts with sk-gt- and is shown only once.
  • Set a daily or monthly spend limit if you'd like a safety net while testing. You can raise it later.

2. Store the key as an environment variable

Keep the key out of your code. Add it to your environment or secrets manager:

Shell
export GREENTOKENS_API_KEY="sk-gt-…"

3. Change the base URL

This is the actual switch. Where you create your SDK client, point it at GreenTokens and pass the new key. The only thing to watch is the URL: OpenAI SDKs use it with /v1, Anthropic SDKs without.

Python · OpenAI SDK
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.greentokens.io/v1",
    api_key=os.environ["GREENTOKENS_API_KEY"],
)
TypeScript · OpenAI SDK
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://api.greentokens.io/v1",
  apiKey: process.env.GREENTOKENS_API_KEY,
})
Python · Anthropic SDK
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.greentokens.io",  # no /v1: the SDK adds it
    api_key=os.environ["GREENTOKENS_API_KEY"],
)

If your app creates the client without arguments and reads its settings from the environment, you can switch without touching code at all by setting the variables the SDK already reads:

Shell
# OpenAI SDKs
export OPENAI_BASE_URL="https://api.greentokens.io/v1"
export OPENAI_API_KEY="$GREENTOKENS_API_KEY"

# Anthropic SDKs
export ANTHROPIC_BASE_URL="https://api.greentokens.io"
export ANTHROPIC_API_KEY="$GREENTOKENS_API_KEY"

4. Check your model IDs

Most model names are the same as the ones you use today, such as claude-sonnet-5 or gpt-6-sol. To see every ID GreenTokens accepts, list the models (no key needed) or browse the models page:

Shell
curl https://api.greentokens.io/v1/models

If your code uses a dated snapshot name or an alias that isn't in the list, replace it with the matching ID from the list. Responses echo back the ID you sent.

5. Send a test request

Run one request through the new client and check three things: you get an answer, the model in the response is the one you asked for, and the request shows up in your dashboard.

Python
raw = client.chat.completions.with_raw_response.create(
    model="claude-sonnet-5",
    messages=[{"role": "user", "content": "Reply with the word ready."}],
)
response = raw.parse()

print(response.choices[0].message.content)  # ready
print(response.model)                       # claude-sonnet-5
print(raw.headers["x-request-id"])          # find this in the Requests log

Open the Requests page in the dashboard: the call appears with its model, tokens, cost and latency. If you use streaming, tools or image inputs, run one request of each kind too; they work the same way through GreenTokens.

6. Roll it out

  1. Use a separate key per environment (development, staging, production) so their usage and limits stay apart.
  2. Deploy to a small share of traffic first if your setup allows it, and compare error rates and latency.
  3. Watch the Requests log and your balance for the first day. Top up before the balance runs low: requests are refused, not billed, once it's empty.
  4. Set spend limits that match expected usage, so an unexpected spike can't drain the balance.

Troubleshooting

You seeLikely causeFix
401Key missing, mistyped, paused or revokedCheck the key and that it's being sent
404Model ID not recognised, or /v1 missing or doubledUse an ID from /v1/models; check the base URL
402Balance empty, or the key's spend limit reachedTop up, or raise the key's limit

The errors page lists every status code. For anything else, contact support with the x-request-id from the response.

Next steps

More guides