For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

1

Install the package

pip install -U langchain-aimlapi
2

Set your API key

export AIMLAPI_API_KEY=your_key_here
3

Call a model

from langchain_aimlapi import ChatAimlapi

llm = ChatAimlapi(model="openai/gpt-5-5")
print(llm.invoke("Sing a ballad of LangChain.").content)

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:

The base URL is:

Authentication is read from the AIMLAPI_API_KEY environment variable:

Need a key first? Use API Key Management.

Available classes

Class
Use for

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 use

  • anthropic/claude-sonnet-5 — coding and long-form work

  • google/gemini-3.6-flash — lower latency and lower cost

  • openai/text-embedding-3-small — embeddings

For the full catalog, use All Model IDs.

Config checklist

Make sure these values are set:

  • package: langchain-aimlapi

  • API key variable: AIMLAPI_API_KEY

  • base URL: https://api.aimlapi.com/v1 (built in; override with AIMLAPI_API_BASE)

  • model ID: exact AI/ML API model ID, passed as model=

Troubleshooting

I get a model-not-found error

Pass model= explicitly and copy the ID from aimlapi.com/models. IDs are vendor-prefixed; a bare name such as gpt-5-5 is not a catalog ID.

I get an auth error

Check that:

I need a different endpoint

Set AIMLAPI_API_BASE to override the base URL. Leave it unset to use https://api.aimlapi.com/v1/.

Last updated

Was this helpful?