FreeLLMAPI Anthropic Endpoint: Complete Claude Compatibility Implementation

FreeLLMAPI exposes an Anthropic-compatible Messages API at POST /v1/messages that enables Claude clients to connect using standard SDKs when providing the anthropic-version header.

FreeLLMAPI provides dedicated Anthropic endpoint support that allows developers to use official Claude clients and Anthropic SDKs without modification. The implementation routes requests through the platform's unified free model infrastructure by translating Anthropic protocol calls into the internal service architecture.

The Core Anthropic Messages Endpoint

POST /v1/messages

The primary FreeLLMAPI Anthropic endpoint is POST /v1/messages, which fully implements the Anthropic Messages API specification. This route lives in server/src/routes/anthropic.ts and handles chat completions for Claude-family models.

When a client sends a request with the anthropic-version header, FreeLLMAPI processes the message through its internal routing layer, mapping Claude model identifiers to available free models according to the configuration in server/src/services/anthropic-map.ts. The endpoint accepts standard Anthropic request payloads containing model, max_tokens, and messages arrays.

Supporting Anthropic-Compatible Routes

FreeLLMAPI provides additional endpoints that mirror the complete Anthropic API surface when the appropriate headers are present.

GET /v1/models

When clients include the anthropic-version header, the server returns an Anthropic-shaped model list at GET /v1/models. This endpoint filters the internal model catalog to present only Claude-compatible configurations, allowing tools like Claude Code to discover available models through standard Anthropic client methods.

POST /v1/messages/count_tokens

The platform implements token counting functionality at POST /v1/messages/count_tokens. This helper endpoint accepts draft message payloads and returns token estimates using Anthropic-compatible counting logic, enabling client-side request validation before submitting full completion requests.

Routing Architecture and Priority

In server/src/app.ts, the Anthropic router is explicitly mounted before the OpenAI proxy middleware. This sequential mounting ensures that requests bearing the anthropic-version header receive Anthropic-protocol responses rather than OpenAI-shaped payloads. The routing logic performs content negotiation based on header detection, directing traffic to the appropriate handler without requiring separate base URLs.

The implementation in server/src/routes/anthropic.ts includes request validation, authentication checks against the unified API key system, and error handling that returns Anthropic-compatible error shapes to maintain SDK compatibility.

Authentication Requirements

All FreeLLMAPI Anthropic endpoint requests require two specific headers:

  • x-api-key – Your FreeLLMAPI unified API key used for authentication across all provider endpoints
  • anthropic-version – The API version string (e.g., 2023-06-01) that triggers Anthropic routing mode

The anthropic-version header serves dual purposes: it authenticates the request as Anthropic-protocol and determines the response format version returned by the server.

Model Mapping and Configuration

The mapping between Anthropic model identifiers and internal FreeLLMAPI models is handled by server/src/services/anthropic-map.ts. This service translates requests for specific Claude model variants (such as claude-3-sonnet-20240229 or claude-3-opus-20240229) into the appropriate backend model configurations.

Administrators can customize this mapping through server/src/routes/settings.ts, which exposes GET and PUT endpoints for /anthropic-map. This allows runtime modification of model routing without restarting the service, enabling dynamic configuration of which internal models serve specific Claude API requests.

Practical Implementation Examples

Sending a Chat Completion Request

import fetch from 'node-fetch';

const response = await fetch('http://localhost:3000/v1/messages', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_UNIFIED_API_KEY',
    'anthropic-version': '2023-06-01',
  },
  body: JSON.stringify({
    model: 'claude-3-sonnet-20240229',
    max_tokens: 512,
    messages: [
      { role: 'user', content: 'Explain quantum tunneling in simple terms.' },
    ],
  }),
});

const data = await response.json();
console.log(data);

Retrieving the Model List

const res = await fetch('http://localhost:3000/v1/models', {
  headers: {
    'anthropic-version': '2023-06-01',
    'x-api-key': 'YOUR_UNIFIED_API_KEY',
  },
});
const models = await res.json();
console.log(models);

Counting Tokens Before Sending

await fetch('http://localhost:3000/v1/messages/count_tokens', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'anthropic-version': '2023-06-01',
    'x-api-key': 'YOUR_UNIFIED_API_KEY',
  },
  body: JSON.stringify({
    model: 'claude-3-opus-20240229',
    messages: [{ role: 'user', content: 'Hello, world!' }],
  }),
});

Summary

  • FreeLLMAPI Anthropic endpoint is available at POST /v1/messages and implements the complete Anthropic Messages API specification.
  • Supporting endpoints include GET /v1/models for model discovery and POST /v1/messages/count_tokens for token estimation.
  • The routing logic resides in server/src/routes/anthropic.ts and is mounted before OpenAI handlers in server/src/app.ts.
  • Requests require both the x-api-key and anthropic-version headers to activate Anthropic compatibility mode.
  • Model mapping is configurable through server/src/services/anthropic-map.ts and adjustable via the settings API in server/src/routes/settings.ts.

Frequently Asked Questions

What is the main FreeLLMAPI Anthropic endpoint for Claude compatibility?

The primary endpoint is POST /v1/messages, which implements the Anthropic Messages API specification. When combined with the anthropic-version header, this endpoint accepts standard Claude client requests and returns Anthropic-formatted responses, enabling compatibility with official SDKs and Claude Code.

Which HTTP headers are required to use the Anthropic endpoints?

You must include x-api-key containing your FreeLLMAPI unified key and anthropic-version (such as 2023-06-01) to activate Anthropic routing. The anthropic-version header triggers the server to return Anthropic-shaped payloads rather than OpenAI-formatted responses.

How does FreeLLMAPI handle model mapping for Claude requests?

The server/src/services/anthropic-map.ts file contains the translation logic that maps Claude model identifiers (like claude-3-sonnet-20240229) to the platform's internal model catalog. Administrators can modify these mappings through the /anthropic-map settings endpoints exposed in server/src/routes/settings.ts.

Where is the Anthropic routing logic configured in the source code?

The Anthropic router is defined in server/src/routes/anthropic.ts and integrated into the Express application in server/src/app.ts. Mounting occurs before the OpenAI proxy middleware, ensuring that requests with Anthropic headers receive protocol-appropriate responses.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →