AI APIs: Protocol, API Key, and First Request
Choose the correct AI API protocol, keep the key safe, send a minimal request, and verify the response and usage record.
Contents
Before connecting an AI API, identify the contract your client expects: OpenAI-compatible or Anthropic-compatible. Then use the provider’s documented Base URL, keep the API key outside source code, send one short request, and verify both the response and its usage record. A settings screen that saves successfully does not prove that the request reached the intended endpoint.
If you need an API gateway rather than a vendor-specific web subscription, start with the BetterToken AI API overview. BetterToken exposes separate OpenAI-compatible and Anthropic-compatible interfaces. You still use your own BetterToken account and API key; the key is not an OpenAI or Anthropic Console key.
API access, web subscriptions, and shared accounts
These are different products:
| Access path | What you receive | What it does not imply |
|---|---|---|
| API access | HTTP requests authenticated with your own key | Access to a vendor’s consumer chat subscription |
| Web subscription | A specific product interface and its included limits | A transferable API balance or third-party API key |
| Shared account | Someone else’s login session | A safe or suitable production integration |
For normal development, use an account and key you control. Do not build an integration around a purchased or shared login.
1. Choose the protocol from the client
Read the client or SDK documentation before choosing a model. Use OpenAI-compatible when the tool expects an OpenAI SDK, Chat Completions, Responses API, or a field such as OPENAI_BASE_URL. Use Anthropic-compatible when it creates Messages requests and expects ANTHROPIC_BASE_URL or x-api-key.
The model name does not determine the protocol. The client must create the same request contract accepted by the endpoint.
For BetterToken, the Base URLs are:
OpenAI-compatible Base URL: https://www.bettertoken.ai/v1?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch
Anthropic-compatible Base URL: https://bettertoken.ai/?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch
The OpenAI-compatible value already includes /v1. The Anthropic-compatible value does not; a raw Messages request uses the full resource path /v1/messages.
2. Distinguish a Base URL from a request path
An SDK or tool normally asks for a Base URL and appends its resource path. A direct HTTP call needs the full path.
OpenAI-compatible raw path: https://www.bettertoken.ai/v1/chat/completions?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch
Anthropic Messages raw path: https://www.bettertoken.ai/v1/messages?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch
Do not paste a full request path into a field that expects only a Base URL. Otherwise the client may append the resource twice and return 404.
3. Keep the API key outside code
Use local environment variables for the first test, then move production credentials to the secret manager provided by your platform.
export BETTERTOKEN_API_KEY="your_api_key_here"
export BETTERTOKEN_MODEL_ID="your_current_model_id"
Never put a real key in source code, .env.example, a prompt, an issue, a screenshot, or a support message. Copy the current exact Model ID from the provider’s documentation or model catalog instead of guessing it from a marketing name.
4. Send a minimal OpenAI-compatible request
Use a short text-only request before enabling streaming or tools:
curl https://www.bettertoken.ai/v1/chat/completions?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch \
-H "Authorization: Bearer $BETTERTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$BETTERTOKEN_MODEL_ID"'",
"messages": [{"role": "user", "content": "Reply with API_OK"}],
"max_tokens": 16
}'
Avoid curl -v in logs shared with other people because verbose output can expose sensitive headers.
5. Send a minimal Anthropic-compatible request
The Messages request uses a different authentication header and body shape:
curl https://www.bettertoken.ai/v1/messages?utm_source=blog&utm_medium=organic_content&utm_campaign=SEO-080&utm_content=api-neyrosetey-v-rossii-protokol-klyuch \
-H "x-api-key: $BETTERTOKEN_API_KEY" \
-H "anthropic-version: CURRENT_SUPPORTED_VERSION" \
-H "Content-Type: application/json" \
-d '{
"model": "'"$BETTERTOKEN_MODEL_ID"'",
"max_tokens": 16,
"messages": [{"role": "user", "content": "Reply with API_OK"}]
}'
CURRENT_SUPPORTED_VERSION is a placeholder. Confirm the currently supported header in the API reference before testing. If your task is specifically Claude-compatible access, review the Claude API setup and access boundaries before returning to the minimal request.
6. Verify the response and usage record
The first test is complete only when these signals agree:
- the HTTP status indicates success;
- the response contains the expected model ID or its documented display value;
- the selected contract returns the expected content and
usagefields; - BetterToken Workspace shows a record at the same time with the model, status, applicable input/output/cache tokens, and charge.
Workspace is a usage and billing record. Do not assume it stores the complete prompt or response body. Use the current model catalog for availability and pricing rather than copying a dynamic list into your integration notes.
7. Troubleshoot by response layer
- 401 or 403: check the key, key group, whitespace, Base URL, and the authentication header required by the chosen protocol.
- 404: compare the Base URL with the full path. Look for a duplicated
/v1,/chat/completions, or/messages. - model not found: copy the current exact Model ID and confirm that it is available for the selected key group and protocol.
- 429: read the response body, respect any retry delay, and check current concurrency or rate limits before sending one more request.
- Timeout or TLS error: separate local proxy, firewall, DNS, and certificate conditions from an API response. Do not permanently disable TLS verification.
- No Workspace record: make sure an old environment variable did not route the request to another provider.
After changing the configuration, send one short request again and match it to Workspace. Once that works, add streaming, tools, longer context, or an agent loop one layer at a time so each new failure has a small diagnostic surface.
Next step: an OpenAI-compatible API path
For a practical setup path using your own key and an OpenAI-compatible route, see the OpenAI API page. It describes a BetterToken-compatible API, not an official OpenAI key. If your current integration uses OpenRouter, compare the requirements before changing the production route on OpenRouter alternatives.