gradiated

Use the OpenAI SDK

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

Use the openai package for Python or Node. The same client can send your existing Chat Completions requests to Gradiated.

Install

pip install openai

Chat Completions

from openai import OpenAI
import os

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

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

print(response.choices[0].message.content)

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

Responses API

Use the same client for Responses requests.

response = client.responses.create(
    model="YOUR_MODEL_ID",
    input="Explain inference in one sentence.",
    extra_body={"service_tier": "default"},
)

print(response.output_text)

Gradiated does not support stored Responses state. Send the complete input with each request.

Stream output

Streaming returns text while the model is still generating it.

stream = client.chat.completions.create(
    model="YOUR_MODEL_ID",
    messages=[{"role": "user", "content": "Write one short sentence."}],
    stream=True,
)

for chunk in stream:
    text = chunk.choices[0].delta.content
    if text:
        print(text, end="", flush=True)

Call tools

Send function definitions with the request. Your application validates the arguments and runs the selected function.

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

tool_calls = response.choices[0].message.tool_calls

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