cheapaimodel

Anthropic SDK

Use the official Anthropic Python and TypeScript SDKs with cheapaimodel.

Copy

Not available yet. No model in the catalog currently lists the Anthropic Messages endpoint (/v1/messages). Use the OpenAI SDK for now. This guide applies once a model's catalog page lists /v1/messages.

The Anthropic SDKs call /v1/messages. Set the base URL without /v1; the SDK adds the path itself.

Terminal
pip install anthropic
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.cheapaimodel.ai",
    api_key=os.environ["CHEAPAIMODEL_API_KEY"],
)

message = client.messages.create(
    model="<model-id>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain recursion in one sentence."}],
)
print(message.content[0].text)

Environment variables

Terminal
export ANTHROPIC_BASE_URL="https://api.cheapaimodel.ai"
export ANTHROPIC_API_KEY="$CHEAPAIMODEL_API_KEY"

Replace <model-id> with a model from the catalog that lists /v1/messages.

Copy
Open in

On this page