This package contains the LangChain integration with Aimlapi. AI/ML API provides over 300 models including Deepseek, Gemini and ChatGPT. All models are served with enterprise-grade rate limits and uptimes via Aimlapi.
pip install -U langchain-aimlapiConfigure credentials by setting the environment variable:
AIMLAPI_API_KEY– your AI/ML API key
The package exports the following classes:
ChatAimlapi– chat completion modelAimlapiLLM– text completion modelAimlapiEmbeddings– embeddingsAimlapiImageModel– image generationAimlapiVideoModel– video generationAIMLAPI_HEADERS– default request headers
All classes provide both synchronous and asynchronous APIs. See the docs/ folder for complete examples.
ChatAimlapi class exposes chat models from Aimlapi.
from langchain_aimlapi import ChatAimlapi
llm = ChatAimlapi()
llm.invoke("Sing a ballad of LangChain.")AimlapiEmbeddings class exposes embeddings from Aimlapi.
from langchain_aimlapi import AimlapiEmbeddings
embeddings = AimlapiEmbeddings()
embeddings.embed_query("What is the meaning of life?")AimlapiLLM class exposes LLMs from Aimlapi.
from langchain_aimlapi import AimlapiLLM
llm = AimlapiLLM()
llm.invoke("The meaning of life is")AimlapiImageModel generates images from prompts.
from langchain_aimlapi import AimlapiImageModel
img = AimlapiImageModel(
model="stable-diffusion-v3-medium",
size="512x512",
n=1,
)
img.invoke("A serene mountain lake at sunset")AimlapiVideoModel generates short videos from prompts.
from langchain_aimlapi import AimlapiVideoModel
vid = AimlapiVideoModel(
model="veo2",
)
vid.invoke("A timelapse of city lights at night")