LangChain

Point LangChain's ChatOpenAI at AI Nexus, with Python and JavaScript examples.

LangChain's ChatOpenAI accepts a custom base URL, so you can point it straight at the AI Nexus OpenAI-compatible API. You can use any model on the model square that supports /v1/chat/completions.

Verification status

The examples follow LangChain's official documentation and have not all been tested against AI Nexus. Only two values matter: Base URL and API Key.

Put your key in an environment variable first:

export MYAIEXP_API_KEY="sk-xxxxxxxx"

Python

pip install langchain-openai
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="your-model-id",  # replace with a model ID from the model square
    api_key=os.environ["MYAIEXP_API_KEY"],
    base_url="https://ai.myaiexp.com/v1",
)

print(llm.invoke("Introduce yourself in one sentence.").content)

JavaScript / TypeScript

npm install @langchain/openai
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "your-model-id", // replace with a model ID from the model square
  apiKey: process.env.MYAIEXP_API_KEY,
  configuration: { baseURL: "https://ai.myaiexp.com/v1" },
});

const res = await llm.invoke("Introduce yourself in one sentence.");
console.log(res.content);

Notes

  • Streaming, bind_tools and similar features use the OpenAI format underneath; see Streaming and Function calling for gateway support.
  • Model names must exactly match GET /v1/models; see the model square for the full list.
  • For Claude-native features (such as Prompt caching), you can use ChatAnthropic from langchain-anthropic with base URL https://ai.myaiexp.com (no /v1). Pick a model that supports /v1/messages; see Anthropic format.

This service is provided for learning and research purposes only. Please follow each model provider's usage policies.

On this page