Skip to main content

Use AI gateway with SDKs Early availability

Use the OpenAI and Anthropic SDKs with the Aiven AI Gateway.

Prerequisites​

Use the OpenAI SDK​

  1. To install the SDK, run:

    uv add openai
  2. Send a request:

    from openai import OpenAI

    client = 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​

  1. To install the SDK, run:

    uv add anthropic
  2. Send a request:

    from anthropic import Anthropic

    client = 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_KEY is 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.