gradiated

Use the Anthropic SDK

Keep your Messages request. Change the base URL, API key, and model ID.

Use anthropic for Python or @anthropic-ai/sdk for Node. The same client can send your existing Messages requests to Gradiated.

Install

pip install anthropic

Messages

from anthropic import Anthropic
import os

client = Anthropic(
    base_url="https://api.gradiated.com",
    api_key=os.environ["GRADIATED_API_KEY"],
)

message = client.messages.create(
    model="YOUR_MODEL_ID",
    max_tokens=256,
    messages=[
        {"role": "user", "content": "Explain inference in one sentence."}
    ],
    extra_body={"service_tier": "default"},
)

print(message.content[0].text)

Choose an exact ID from models and pricing. This example uses the default service tier.

Stream output

Streaming returns text while the model is still generating it.

with client.messages.stream(
    model="YOUR_MODEL_ID",
    max_tokens=256,
    messages=[{"role": "user", "content": "Write one short sentence."}],
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)

Call tools

Send tool definitions with the request. Your application validates the input and runs the selected tool.

message = client.messages.create(
    model="YOUR_MODEL_ID",
    max_tokens=256,
    messages=[{"role": "user", "content": "What is the weather in Warsaw?"}],
    tools=[{
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "input_schema": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    }],
)

tool_uses = [block for block in message.content if block.type == "tool_use"]

Return each result in a tool_result block before you continue the conversation.

Check service tiers, model parameters, and retry behavior before deploying to production.