Frameworks
LangChain
Call APIKO chat models from LangChain in Python or JavaScript
Overview
LangChain's OpenAI chat model class works with APIKO unchanged: point its base URL at the gateway and use any chat model id from the catalog, including Claude, Gemini and DeepSeek models.
Prerequisites
- Python 3.10 or later, or Node.js 22 or later
- An APIKO API Key from Console → API Keys, saved in the
APIKO_API_KEYenvironment variable
Step 1: Install LangChain
bash
pip install -U langchain-openaiStep 2: Point LangChain at APIKO
python
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-6.1-sol",
base_url="https://api.apiko.app/v1",
api_key=os.environ["APIKO_API_KEY"],
)
reply = llm.invoke("Reply with the word ok")
print(reply.content)
print(reply.usage_metadata)Swap gpt-6.1-sol for any chat model id returned by GET /v1/models for your key.
Step 3: Verify Configuration
Run the script. You should see ok followed by the token counts, and the request in Console → Task Logs. A 401 means the key is wrong, a 403 usually means the balance is empty, and a 404 model_not_found means the model id is not available to your key.
Notes
- Streaming works as usual with
llm.stream(...). - Image and video models run as asynchronous tasks; call them through the task API instead of the chat class.
- Tested against the APIKO gateway on 2026-09-30 with langchain-openai 1.6.6 (Python) and @langchain/openai 1.6.0 (JavaScript).