Skip to content

OpenAI Compatible API Key: Meaning and Setup

Updated · TokenomixAI

An openai compatible api key is an access key for an endpoint that accepts requests shaped like OpenAI chat completions, so a client that lets you set a base URL needs only a URL and key swap. TokenomixAI issues sk-tkx- keys for many text and code models behind one base URL.

An OpenAI-compatible key only means the request shape matches OpenAI, so switching base URL and key replaces rewriting client code.

What Does an OpenAI-Compatible API Key Mean?

OpenAI-compatible describes the request shape rather than the vendor behind it. The endpoint expects a model field, a messages field and an Authorization header in the layout OpenAI chat completions define.

Compatibility is what allows reuse. A library or tool that accepts a custom base URL can send the same request body to another host, and the key valid on that host is the only credential that changes.

The models behind the endpoint are a separate question from compatibility. Names sit on the model list in the documentation, and each request names one in the model field. On TokenomixAI a single sk-tkx- key covers text and code models, including some that take images as input (vision). No image, video or audio generation is offered.

The sk-tkx- Key Format and How to Send It

TokenomixAI keys start with sk-tkx- and travel in the Authorization header with the Bearer scheme, the convention OpenAI keys follow.

  • Header: Authorization: Bearer sk-tkx-... on every request.
  • Keep the key out of query strings and URLs, where logs and shell history can capture it.
  • Store it in an environment variable or a secret manager rather than a committed file.
  • One key serves the SDK, OpenCode, Claude Code, n8n and curl scripts.

The key is issued after a package is bought on the website. No account and no credit card are required; payment is QRIS in Indonesia or USDT, and the key is sent once payment completes.

Every tool reads the same string, so one stored copy covers all projects on that account. Separate credentials per project are not required, and a top-up leaves the key unchanged.

How to Use the Key in the OpenAI SDK and curl

The Python openai library accepts a base_url and an api_key. Point base_url at https://api.tokenomixai.com/v1 and pass the sk-tkx- key as api_key.

from openai import OpenAI

client = OpenAI(base_url="https://api.tokenomixai.com/v1", api_key="sk-tkx-...")
reply = client.chat.completions.create(
    model="MODEL_ID",  # salin ID model dari tokenomixai.com/docs
    messages=[{"role": "user", "content": "Halo"}],
)
print(reply.choices[0].message.content)

Without a library, the chat completions endpoint takes a direct HTTP call with curl. The key goes in the same Authorization header.

curl https://api.tokenomixai.com/v1/chat/completions \
  -H "Authorization: Bearer sk-tkx-..." \
  -H "Content-Type: application/json" \
  -d '{"model": "MODEL_ID", "messages": [{"role": "user", "content": "Halo"}]}'

The model field has to name a model from the list in the documentation, since available models and multipliers live on the website and change over time. For SDK and curl calls the base URL keeps the /v1 suffix.

The gateway also exposes an Anthropic-compatible /v1/messages endpoint for clients that use that protocol, so a single key covers both request families.

The Same Key in n8n, OpenCode and Other Tools

In n8n, a credential holds the base URL https://api.tokenomixai.com/v1 and the sk-tkx- key, and the node that calls the model references that credential. One credential can be reused across workflows.

OpenCode sets up with a single command on macOS or Linux. The script asks for the key, which is never placed in a URL.

bash <(curl -fsSL https://tokenomixai.com/install/opencode.sh)

The installer writes a provider named tokenomixai into the provider object of ~/.config/opencode/opencode.json (on Windows, %USERPROFILE%\.config\opencode\opencode.json). That value is an object, not an array, and uses the npm package @ai-sdk/openai-compatible with options baseURL and apiKey. Other providers, MCP entries and plugins stay in place, and a backup is written first. Set by hand, the entry follows this shape:

{
  "provider": {
    "tokenomixai": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.tokenomixai.com/v1",
        "apiKey": "sk-tkx-..."
      }
    }
  }
}

Reversal uses the same installer with --restore on macOS or Linux, or the RESTORE environment variable set before the command on Windows PowerShell. Editor workflow beyond initial setup is covered in How to Use OpenCode.

Claude Code follows a different rule. ANTHROPIC_BASE_URL takes https://api.tokenomixai.com with no /v1, paired with ANTHROPIC_AUTH_TOKEN for the key, because Claude Code appends /v1/messages itself. The variable list appears in Anthropic Base URL and Auth Token.

ToolWhat to set
OpenAI SDK (Python)base_url and api_key
curlEndpoint URL and Authorization header
n8nBase URL and key inside a credential
OpenCodeInstaller, or the tokenomixai provider in the config
Claude CodeANTHROPIC_BASE_URL without /v1 and ANTHROPIC_AUTH_TOKEN

How Do Quota, Rate Limit and Expiry Work?

Quota counts tokens rather than time windows. A key keeps working while tokens remain and before expiresAt passes, so no five-hour window applies.

The quota endpoint reports the current state of the key. It takes the key in the Authorization header.

curl https://api.tokenomixai.com/v1/quota -H "Authorization: Bearer sk-tkx-..."

The response carries status (active or exhausted), remainingTokens, maxTokens, usagePercent, expiresAt, and low, a flag that turns true at 10 percent or less remaining.

A rate limit sits on top of quota: 600 requests per minute per account, shared by every key on that account. Above that ceiling the API answers 429 with a Retry-After header carrying the interval to wait before the next attempt.

Top-ups combine with the remaining balance, and validity follows the latest top-up. The key does not change, so credentials already stored in tools stay valid.

Which Errors Appear When Setting Up the Key?

  • 401 Unauthorized: the key is mistyped or expired, or the header lacks the Bearer scheme.
  • 404 or an empty body: the base URL is missing /v1, except for Claude Code, which must omit it.
  • 429 Too Many Requests: the account passed 600 requests per minute; wait the Retry-After interval.
  • Model not found: the model field holds a name that is not on the documented list.

Gateway logging covers request metadata only, such as model, token count, time and status. Prompts and completions are not stored, so source code inside a request is not retained.

Several agents running together multiply the request rate, so quota is worth checking before a large batch starts. Honouring Retry-After on each retry keeps the total under the per-minute ceiling.

Frequently asked questions

Can an OpenAI API key be used with TokenomixAI?

No. Keys from other providers do not work on the TokenomixAI gateway; a key starting with sk-tkx- is needed, and it is sent after a package is bought. Compatibility covers the request and response shape, not the key.

Does one key work for every model?

Yes. A single sk-tkx- key covers the text and code models on the list, and the model field on each request selects one. Model names sit in the documentation because the list changes.

Can the same key run in several tools at once?

Yes. One sk-tkx- key serves the SDK, OpenCode, Claude Code, n8n and curl scripts without separate credentials. All of that traffic draws on the same ceiling of 600 requests per minute for the account.

Why does a request return 429 while quota remains?

The 429 comes from the rate limit, not the quota. The ceiling is 600 requests per minute per account and applies across all keys on it, so parallel scripts can reach it together. Read Retry-After and pause for that interval.

Where should the key live in a project?

In an environment variable or a secret manager, read at runtime by the code. A key pasted into a committed file or a URL query string can end up in logs and shell history.

More articles