Skip to main content
Use the OpenAI SDK with Base URL https://bettertoken.ai/v1, or the Anthropic SDK with https://bettertoken.ai. The examples below send a short text request through Chat Completions, Responses, or Messages using your BetterToken API Key.

Choose an SDK and Base URL

The SDK adds the endpoint path and authentication headers. The Anthropic SDK also sends the API version header. See the protocol comparison if you are adapting existing code.

Prerequisites

Complete the quickstart to create a BetterToken API Key and add credit. Copy a Model ID from the model plaza that is available for the endpoint you plan to call. Replace both placeholders below before running a request. Set these variables in the terminal where you will run the examples. The shell commands on this page use macOS / Linux syntax:
For Python, install the SDKs inside your project’s virtual environment:
For JavaScript, install the packages in your project and save each example as a separate .mjs file, then run it with node:
All examples read the Key from BETTERTOKEN_API_KEY. They disable SDK retries so one test does not silently become several attempts. For application retry policies, see errors and limits.

Call Chat Completions

Use messages for the input conversation. A successful text response contains choices[0].message.content.

Call Responses

Use input for the prompt. OpenAI SDKs expose output_text as a text convenience property; the HTTP JSON response contains an output array. Inspect message items and their text content rather than assuming every output item is text.

Call Messages

Use messages and supply max_tokens. For this short text request, a successful text response includes a text block such as content[0].text. In general, iterate through content and read only blocks with type: "text".

Common errors

Can I reuse one Key for both SDKs?

Yes. One BetterToken API Key works with all available models. Use the Base URL and request format for each SDK.

Can I add streaming, tools, or structured output?

Streaming and tool calling support varies by model. Test a small request with your Model ID first; follow streaming and tool calling. For JSON validation and model-dependent structured output, see the structured JSON FAQ.

Official references