AI/ML API

Use AI/ML API with access to 300+ models in Agno agents.

AI/ML API provides unified access to 300+ AI models, including models from OpenAI, Anthropic, Google, and DeepSeek.

Authentication

Set your AIMLAPI_API_KEY environment variable. Get your key at aimlapi.com.

export AIMLAPI_API_KEY="your_value_here"

Example

Install Agno and the openai package:

uv pip install -U agno openai

This example uses the provider's GPT-5.2 route, openai/gpt-5-2.

from agno.agent import Agent
from agno.models.aimlapi import AIMLAPI

agent = Agent(
    model=AIMLAPI(id="openai/gpt-5-2"),
    markdown=True,
)

agent.print_response("Explain how black holes are formed.")

Parameters

Select a model ID from the provider's current catalog.

ParameterTypeDefaultDescription
idstr"gpt-5.6-luna"The ID of the model to use
namestr"AIMLAPI"The name of the model
providerstr"AIMLAPI"The provider of the model
api_keyOptional[str]NoneThe API key for AI/ML API (defaults to AIMLAPI_API_KEY env var)
base_urlstr"https://api.aimlapi.com/v1"The base URL for the AI/ML API
max_tokensint4096Maximum number of tokens to generate

AIMLAPI extends the OpenAI-compatible interface and supports most parameters from the OpenAI model, where applicable.

Available Models

AI/ML API serves 300+ models from OpenAI, Anthropic, Google, Meta, DeepSeek, and others. The catalog changes often, so check the model database for current model IDs.

Request attribution

The adapter adds fixed HTTP-Referer, X-Title, X-AIMLAPI-Partner-ID, and X-AIMLAPI-Source headers. Inspect their values through agno.models.aimlapi.AIMLAPI_HEADERS. Pass default_headers to override them; caller values take precedence case-insensitively.