Claude Messages API compatibility

Anthropic-compatible API gateway and Claude endpoint

Connect Anthropic SDK clients to Claude models through one CLODEX account while preserving Messages API content blocks, streaming events and tool calls.

Anthropic-compatible endpoint and base URL

Anthropic SDKs append the Messages API path, so configure https://clodex.xyz as the base URL without a trailing /v1. Use the exact Claude model identifier visible to your CLODEX key. A Claude API proxy should preserve content-block structure and terminal events rather than flattening everything into plain text.

Compatibility should be verified with the same SDK version used in production. Test system instructions, multi-part content, streaming, tool use and error envelopes separately. A provider can support basic text while behaving differently for advanced features.

Anthropic Python SDK example

The SDK sends requests to /v1/messages. Keep the key server-side and set explicit output limits. If a model is unavailable, surface that error instead of silently switching to a different Claude tier with different cost or behavior.

from anthropic import Anthropic

client = Anthropic(
    api_key="clodex_YOUR_KEY",
    base_url="https://clodex.xyz",
)

message = client.messages.create(
    model="claude-opus-5",
    max_tokens=1200,
    messages=[{"role": "user", "content": "Review this API design"}],
)
print(message.content[0].text)

Claude streaming and tool-use contract

A complete Anthropic stream ends with message_stop. If the connection closes after a delta but before the terminal event, treat the result as incomplete even if partial text was displayed. This distinction matters for code changes, database writes and any workflow with external side effects.

Tool calls are untrusted model output. Validate the tool name, JSON schema, current user permissions and business rules after every call. Use idempotency keys for operations that might be retried and require human confirmation for destructive actions.

  • Handle message_start, content_block_delta, message_delta and message_stop.
  • Reject malformed or unexpected tool arguments.
  • Do not retry a non-idempotent action after an ambiguous disconnect.
  • Record request ID and the last valid stream event for diagnostics.

When to use an Anthropic-compatible API gateway

A gateway is useful when a team wants one account and operational layer for Claude plus other model families, or when applications need consistent key management and usage reporting. It does not remove the need to understand Anthropic-specific concepts such as content blocks, prompt caching and tool results.

Evaluate quality and latency with real repositories and conversations. Claude models can differ significantly by tier, and model availability can change. Keep required model checks in deployment automation and publish a clear fallback policy to application owners.

Frequently asked questions

What base URL should the Anthropic SDK use?

Use https://clodex.xyz without /v1 because the SDK appends /v1/messages.

Is this the same endpoint used by Claude Code?

Yes. Claude Code also uses the Anthropic-compatible base URL and a CLODEX API key.

How do I know a Claude stream completed?

Require the message_stop terminal event; a plain connection close is not sufficient.

Connect CLODEX API to your application

One key-management layer, compatible endpoints and several LLM families for apps, agents and developer tools.