> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Count Tokens

The Prisma AIRS AI Gateway supports the [token counting endpoint from anthropic](https://docs.anthropic.com/en/docs/build-with-claude/token-counting) across vertex-ai, bedrock and anthropic in the same format. This allows use to use claude code and any other tooling with the same API signature across providers.

# Examples

<CodeGroup>
  ```sh cURL theme={"system"}
  curl https://aigw.portkey.ai/v1/messages/count_tokens \
      --header "Authorization: Bearer $PORTKEY_API_KEY" \
      --header "content-type: application/json" \
      --data '{
        "model": "@your-provider-slug/your-model-name",
        "system": "You are a scientist",
        "messages": [{
          "role": "user",
          "content": "Hello, Claude"
        }]
      }'
  ```

  ```py Python theme={"system"}
  import anthropic

  client = anthropic.Anthropic(
      api_key="dummy", # auth happens via the Authorization header
      default_headers={"Authorization": "Bearer YOUR_PORTKEY_API_KEY"},
      base_url="https://aigw.portkey.ai"
  )

  response = client.messages.count_tokens(
      model="@your-provider-slug/your-model-name",
      system="You are a scientist",
      messages=[{
          "role": "user",
          "content": "Hello, Claude"
      }],
  )

  print(response.json())
  ```

  ```ts TypeScript theme={"system"}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: 'dummy', // auth happens via the Authorization header
    baseURL: "https://aigw.portkey.ai/v1",
    defaultHeaders: { "Authorization": "Bearer YOUR_PORTKEY_API_KEY" }
  });

  const response = await client.messages.countTokens({
    model: '@your-provider-slug/your-model-name',
    system: 'You are a scientist',
    messages: [{
      role: 'user',
      content: 'Hello, Claude'
    }]
  });

  console.log(response);
  ```
</CodeGroup>


## Related topics

- [AWS Bedrock](/docs/aigw/integrations/llms/bedrock/aws-bedrock.md)
- [Google Vertex AI](/docs/aigw/integrations/llms/vertex-ai.md)
- [Embeddings](/docs/aigw/integrations/llms/openai/embeddings.md)
- [Enterprise Gateway](/docs/aigw/changelog/enterprise.md)
- [Anthropic](/docs/aigw/integrations/llms/anthropic.md)
