SDK guides
LangChain
Use api14 models in LangChain with Python and JavaScript by pointing the OpenAI integration at the api14 base URL and your API key.
LangChain's OpenAI integration works with api14 unchanged: set the base URL and key, and use any model id (for example openai/gpt-5-mini). Examples are shown for Python (langchain-openai) and JavaScript (@langchain/openai).
Install
pip install langchain-openai
# or
npm install @langchain/openai @langchain/core
export API14_API_KEY="sk-api14-..."
Configure (Python)
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="anthropic/claude-sonnet-4.5",
base_url="https://api14.com/api/v1",
api_key=os.environ["API14_API_KEY"],
)
print(llm.invoke("Explain vector databases in two sentences.").content)
Configure (JavaScript)
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "openai/gpt-5-mini",
apiKey: process.env.API14_API_KEY,
configuration: { baseURL: "https://api14.com/api/v1" },
});
const res = await llm.invoke("Explain vector databases in two sentences.");
console.log(res.content);
Streaming
for chunk in llm.stream("Write a haiku about APIs."):
print(chunk.content, end="", flush=True)
for await (const chunk of await llm.stream("Write a haiku about APIs.")) {
process.stdout.write(String(chunk.content));
}
Tools and structured output
from pydantic import BaseModel
from langchain_core.tools import tool
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"21°C in {city}"
msg = llm.bind_tools([get_weather]).invoke("What is the weather in Istanbul?")
print(msg.tool_calls)
class Place(BaseModel):
city: str
country: str
place = llm.with_structured_output(Place).invoke('I live in Lisbon, Portugal.')
print(place)
Embeddings
Most embedding models on api14 are not OpenAI models, so turn off the client-side tiktoken length check:
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(
model="openai/text-embedding-3-small",
base_url="https://api14.com/api/v1",
api_key=os.environ["API14_API_KEY"],
check_embedding_ctx_length=False,
)
vectors = embeddings.embed_documents(["The quick brown fox", "Lorem ipsum"])
Gateway parameters
Pass gateway-specific fields through extra_body (Python) or modelKwargs (JS):
llm = ChatOpenAI(
model="openai/gpt-5-mini",
base_url="https://api14.com/api/v1",
api_key=os.environ["API14_API_KEY"],
extra_body={"models": ["anthropic/claude-sonnet-4.5"], "provider": {"sort": "price"}},
)
Errors
LangChain surfaces the OpenAI SDK exceptions. A 402 insufficient_balance raises openai.APIStatusError; 429 rate_limited raises openai.RateLimitError after the built-in retries (max_retries= on ChatOpenAI). See Errors.