LangChain's OpenAI chat model already accepts a custom base URL, so moving a chain to an OpenAI-compatible provider is a configuration change, not a rewrite. Here is the smallest version, plus the two lines that make it work in a real app.

Install

pip install -U langchain-openai

Point ChatOpenAI at Wren R1

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="wren-r1",
    base_url="https://webwright.ai/v1",
    api_key="www_v1_YOUR_API_KEY",
    temperature=0,
)

response = llm.invoke("Say hello in five words.")
print(response.content)

Or configure it once with environment variables. The langchain-openai client reads OPENAI_BASE_URL and OPENAI_API_KEY, so you can set the connection once and let every OpenAI-compatible client in the app use it.

export OPENAI_BASE_URL="https://webwright.ai/v1"
export OPENAI_API_KEY="www_v1_YOUR_API_KEY"
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="wren-r1", temperature=0)
print(llm.invoke("Say hello in five words.").content)

Stream the answer

for chunk in llm.stream("Write a haiku about latency."):
    print(chunk.content, end="", flush=True)

Read the token usage

response = llm.invoke("Summarize what an OpenAI-compatible API is in one sentence.")
print(response.content)
print(response.usage_metadata)

Transcription is the same base URL. Audio transcription uses the OpenAI-compatible POST /v1/audio/transcriptions endpoint, so it is the same base URL and key. This snippet uses the official openai Python client, as in the other WebWright guides.

from openai import OpenAI

client = OpenAI(base_url="https://webwright.ai/v1", api_key="www_v1_YOUR_API_KEY")

with open("meeting.mp3", "rb") as audio:
    transcript = client.audio.transcriptions.create(
        model="whisper-large-v3-turbo",
        file=audio,
    )

print(transcript.text)

Moving a chain to a second provider is usually a config change. If you would rather have the migration turned into a plan for your own use case, the single consult CTA below is the next step.

The WebWright Team