Your First Claude API Request: API Key, Base URL, and Verification

Create a key, choose the Anthropic-compatible Base URL, send a minimal Messages API request, and verify its token usage.

This is a short, reproducible path from an API key to a verified response in Anthropic Messages API format. If you are still choosing how to purchase and connect to the Claude API, start with the Claude API page for Russia. This guide assumes that you have already created an account and covers only the first technical request.

1. Prepare the API key and Model ID

  1. Register at bettertoken.ai.
  2. Add funds and make sure the amount appears in the Dashboard.
  3. In Your API keys, click Create API key.
  4. Once the key is created, copy the API key and Base URL from the setup window. Then open the current model catalog and copy the selected model's Model ID. Store the key in a secret manager or a local .env file, and never commit it to Git.

The BetterToken quickstart includes step-by-step screenshots for creating a key.

2. Choose the Anthropic-compatible Base URL

For an Anthropic-format request, use:

https://bettertoken.ai

The Base URL for the Anthropic SDK and Claude Code has no /v1 suffix: https://bettertoken.ai. In a raw HTTP request, however, the protocol version is part of the path. The full Messages API address is https://www.bettertoken.ai/v1/messages. The Anthropic SDK appends this path automatically.

3. Send the first request

export ANTHROPIC_API_KEY="ваш_ключ_bettertoken" export ANTHROPIC_BASE_URL="https://bettertoken.ai" export CLAUDE_MODEL_ID="скопируйте_Model_ID_из_текущего_каталога" curl --fail-with-body "$ANTHROPIC_BASE_URL/v1/messages" \ -H "x-api-key: $ANTHROPIC_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d "{ \"model\": \"$CLAUDE_MODEL_ID\", \"max_tokens\": 64, \"messages\": [{\"role\": \"user\", \"content\": \"ping\"}] }"

The line -H "x-api-key: $ANTHROPIC_API_KEY" passes the value of the environment variable you have already set without writing the key into the request text. Replace the key and Model ID placeholders in your local session before running the command. Do not publish the command after substituting a real key.

Model identifiers change. Before sending the request, check the model against the current BetterToken pricing page and API Reference.

4. Check the response and token usage

A successful request returns HTTP 200 and a message JSON object. Check three fields:

  • type equals message;
  • the content array contains the model's response;
  • the usage object contains the input and output token counts.

The response format is documented in the official Anthropic Messages API.

Next, open the BetterToken Dashboard and find the request by time. The record shows the model, status, input/output/cache tokens, and corresponding charge. This verifies both the curl response and the actual accounting for the request.

5. Fix common errors

  • 404 or incorrect route. A raw Anthropic-compatible HTTP request needs the /v1/messages path. /messages is incomplete.
  • 400. Check anthropic-version, content-type, model, max_tokens, and the messages array.
  • 401 or 403. Check the API key, the group selected for it, and the Base URL. Do not send the key to support or include it in a screenshot.
  • 429. Read the response body and retry only after the specified delay. Check the balance and request history in the Dashboard separately.

If the current shell session still contains variables for another provider, clear them before configuring it again:

unset ANTHROPIC_API_KEY unset ANTHROPIC_BASE_URL

After making the fix, repeat the same short request and compare the HTTP response with the Dashboard record again. For the next step—SDKs, streaming, and production configuration—use the current API Reference.

Ready to optimize your LLM workflow?

Join thousands of developers building faster, smarter, and more cost-effective AI applications with BetterToken.