Use AI gateway with SDKs Early availability
Use the OpenAI and Anthropic SDKs with the Aiven AI Gateway.
Prerequisites
- AI Gateway enabled for your organization.
- An API key.
Use the OpenAI SDK
-
To install the SDK, run:
uv add openai -
Send a request:
from openai import OpenAIclient = OpenAI(base_url="https://ai.aiven.io/v1", api_key="API_KEY")response = client.chat.completions.create(model="aiven-model",messages=[{"role": "user", "content": "Say hello"}],)print(response.choices[0].message.content)
aiven-model is the Aiven router, and usage on it is free. To use a specific model, set model to that model's name. Named models are billed at the rates shown in the model list.
Use the Anthropic SDK
-
To install the SDK, run:
uv add anthropic -
Send a request:
from anthropic import Anthropicclient = Anthropic(base_url="https://ai.aiven.io", api_key="API_KEY")message = client.messages.create(model="aiven-model",max_tokens=1024,messages=[{"role": "user", "content": "Say hello"}],)print(message.content[0].text)Where
API_KEYis your AI Gateway API key.
aiven-model is the Aiven router, and usage on it is free. To use a specific model, set model to that model's name. Named models are billed at the rates shown in the model list.