AIMLAPI integration
Warning
You are currently on a page documenting the use of AI/ML API models as text completion models. Many of the latest and most popular AI/ML API models are chat completion models.
You may be looking for the AI/ML API chat docs.
This page helps you get started with AI/ML API text completion models.
Overview
Integration details
| Class | Package | Local | Serializable | JS support | Downloads | Version |
|---|---|---|---|---|---|---|
AimlapiLLM | langchain-aimlapi | ❌ | beta | ❌ |
Model features
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|---|
| ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
Setup
To access AI/ML API models you'll need to create an account, get an API key, and install the langchain-aimlapi integration package.
Credentials
Head to aimlapi.com to sign up and generate an API key. Once you've done this set the AIMLAPI_API_KEY environment variable:
import getpass
import os
if not os.getenv("AIMLAPI_API_KEY"):
os.environ["AIMLAPI_API_KEY"] = getpass.getpass("Enter your AI/ML API key: ")To enable automated tracing of your model calls, set your LangSmith API key:
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")Installation
The LangChain AI/ML API integration lives in the langchain-aimlapi package:
pip install -qU langchain-aimlapiInstantiation
Now we can instantiate our model object and generate text completions:
from langchain_aimlapi import AimlapiLLM
llm = AimlapiLLM(
model="openai/gpt-5-5",
temperature=0.5,
max_tokens=1024,
)Invocation
response = llm.invoke("Explain the bubble sort algorithm in Python.")
print(response)Bubble sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent items, and swaps them when they are out of order. The process repeats until the entire list is sorted. While easy to understand and implement, bubble sort is inefficient on large datasets because it has quadratic time complexity.