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:.mjs file, then run it with node:
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
Usemessages for the input conversation. A successful text response contains choices[0].message.content.
- Python
- JavaScript
- curl
Call Responses
Useinput 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.
- Python
- JavaScript
- curl
Call Messages
Usemessages 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".
- Python
- JavaScript
- curl
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.Related
- API reference overview
- Supported tools
- Errors, status codes, and rate limits
- API Key security and timeouts
- Cache billing rules

