Skip to content

Anthropic API

The Anthropic API uses the Messages format. The common request path is POST /v1/messages. When connecting through Tokeness, set the actual request endpoint to:

txt
https://n.tokeness.dev/v1/messages

Copy the model name from the Tokeness model marketplace. Models in the Claude group use the format described on this page.

Endpoint rules

ScenarioAddress
cURL or hand-written HTTPhttps://n.tokeness.dev/v1/messages
Anthropic SDKhttps://n.tokeness.dev

The Anthropic SDK's messages.create handles the Messages path internally. Set the SDK's base_url or baseURL to the service root address — do not append /v1/messages yourself.

Request fields

FieldValue
Endpointhttps://n.tokeness.dev/v1/messages
API KeyTokeness API key
Headerx-api-key: YOUR_TOKENESS_API_KEY
Versionanthropic-version: 2023-06-01
ModelClaude model name copied from the model marketplace

Verification order

  1. First send a cURL request to https://n.tokeness.dev/v1/messages.
  2. Confirm the request appears in the Tokeness usage logs.
  3. Then use the same key, model name, and SDK root address in the Anthropic SDK.

cURL

bash
curl https://n.tokeness.dev/v1/messages \
  -H "x-api-key: $TOKENESS_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "YOUR_CLAUDE_MODEL_NAME",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Introduce Tokeness in one sentence."
      }
    ]
  }'

Python SDK

For the SDK, set the service root address:

bash
pip install anthropic
py
from anthropic import Anthropic

client = Anthropic(
    api_key="YOUR_TOKENESS_API_KEY",
    base_url="https://n.tokeness.dev",
)

message = client.messages.create(
    model="YOUR_CLAUDE_MODEL_NAME",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Introduce Tokeness in one sentence.",
        }
    ],
)

text = "\n".join(
    block.text
    for block in message.content
    if block.type == "text"
)

print(text)

TypeScript SDK

bash
npm install @anthropic-ai/sdk
ts
import Anthropic from '@anthropic-ai/sdk'

const anthropic = new Anthropic({
  apiKey: 'YOUR_TOKENESS_API_KEY',
  baseURL: 'https://n.tokeness.dev'
})

const message = await anthropic.messages.create({
  model: 'YOUR_CLAUDE_MODEL_NAME',
  max_tokens: 1024,
  messages: [
    {
      role: 'user',
      content: 'Introduce Tokeness in one sentence.'
    }
  ]
})

const text = message.content
  .map((block) => block.type === 'text' ? block.text : '')
  .filter(Boolean)
  .join('\n')

console.log(text)

Differences from the OpenAI format

ItemAnthropic MessagesOpenAI Chat Completions
Path/v1/messages/v1/chat/completions
Key headerx-api-keyAuthorization: Bearer ...
Version headeranthropic-versionNot required
Output fieldcontent[0].textchoices[0].message.content
Token limitmax_tokensmax_tokens or the model-specific field

If the tool only supports OpenAI-compatible providers, use OpenAI-Compatible API instead.

Troubleshooting

SymptomCheck
401Is x-api-key set to your Tokeness API key?
404Is the SDK using https://n.tokeness.dev? Is the cURL endpoint https://n.tokeness.dev/v1/messages?
Version errorDid you include anthropic-version: 2023-06-01?
Model unavailableIs the model name from the Claude group? Does the key have permission to call that model?

OpenAI-compatible access with centralized models, quota, and logs.