LangChain's ChatOpenAI chat model works with Promptix: set the base URL to Promptix and use any model id from the catalog. Chains, agents and tools built on it keep working.
Install
pip install -U langchain-openai langchain-coreConfigure ChatOpenAI
In Python, pass openai_api_base (alias of base_url) and openai_api_key. In JavaScript, pass the base URL in configuration.baseURL.
import osfrom langchain_openai import ChatOpenAI llm = ChatOpenAI( model="openai/gpt-4o-mini", openai_api_base="https://promptix.tn/api/v1", openai_api_key=os.environ["PROMPTIX_API_KEY"], temperature=0.2,) reply = llm.invoke("Translate to French: the invoice is attached.")print(reply.content)Prompts and chains
from langchain_core.output_parsers import StrOutputParserfrom langchain_core.prompts import ChatPromptTemplate prompt = ChatPromptTemplate.from_messages([ ("system", "You write product descriptions for a Tunisian e-commerce site, in {language}."), ("human", "Product: {product}"),]) chain = prompt | llm | StrOutputParser() print(chain.invoke({"language": "French", "product": "Nabeul ceramic plate, hand painted"}))Streaming
for chunk in llm.stream("Give me three tips to learn Tunisian Arabic."): print(chunk.content, end="", flush=True)Structured output
Works on models that support tool calling or JSON schema output.
from pydantic import BaseModel class Invoice(BaseModel): city: str amount_tnd: float extractor = llm.with_structured_output(Invoice)invoice = extractor.invoke("Invoice from Sousse, total due 245.500 dinars.")print(invoice.city, invoice.amount_tnd)Several models, one key
A small factory makes it easy to use a cheap model for simple steps and a stronger one where it matters, all billed to the same Promptix balance:
import osfrom langchain_openai import ChatOpenAI def promptix(model: str, **kwargs) -> ChatOpenAI: return ChatOpenAI( model=model, openai_api_base="https://promptix.tn/api/v1", openai_api_key=os.environ["PROMPTIX_API_KEY"], **kwargs, ) fast = promptix("openai/gpt-4o-mini")smart = promptix("anthropic/claude-sonnet-4", temperature=0)Limitations
Promptix exposes chat completions only. OpenAIEmbeddings and other non-chat OpenAI classes will not work with the Promptix base URL; use a separate embeddings provider for retrieval (RAG) pipelines.