LangChain
Use AI/ML API models in LangChain through the official langchain-aimlapi package.
About
LangChain is a framework for building applications and agents on top of language models — chains, tools, retrieval, and memory, with a common interface across model providers.
AI/ML API is an official LangChain provider: the integration ships as the langchain-aimlapi package on PyPI and is documented in the LangChain docs at docs.langchain.com. One key gives your chains access to chat, text, embedding, image, and video models.
Quick start
When to use AI/ML API with LangChain
AI/ML API works well with LangChain when you want:
chat, embedding, image, and video models behind one key and one package
to swap the model in a chain by changing a string, not a dependency
an OpenAI-compatible provider that also covers non-OpenAI vendors
Prerequisites
Before you start, make sure you have:
Python and LangChain installed
an AI/ML API key from aimlapi.com/app/keys
a model ID from aimlapi.com/models
The base URL is:
Authentication is read from the AIMLAPI_API_KEY environment variable:
Need a key first? Use API Key Management.
Available classes
ChatAimlapi
chat completions
AimlapiLLM
text completions
AimlapiEmbeddings
embeddings
AimlapiImageModel
image generation
AimlapiVideoModel
video generation
All classes provide both synchronous and asynchronous APIs.
Examples
Chat
Embeddings
Image generation
Video generation
Model selection
Always pass model= explicitly and use the exact catalog ID, including the vendor prefix — openai/gpt-5-5, not gpt-5-5.
Good starting models
openai/gpt-5-5— strong general useanthropic/claude-sonnet-5— coding and long-form workgoogle/gemini-3.6-flash— lower latency and lower costopenai/text-embedding-3-small— embeddings
For the full catalog, use All Model IDs.
Config checklist
Make sure these values are set:
package:
langchain-aimlapiAPI key variable:
AIMLAPI_API_KEYbase URL:
https://api.aimlapi.com/v1(built in; override withAIMLAPI_API_BASE)model ID: exact AI/ML API model ID, passed as
model=
Troubleshooting
Links
All Model IDs
Last updated
Was this helpful?