LANGCHAIN OPENAI-COMPATIBLE API

Connect LangChain to an OpenAI-compatible Claude API.

LangChain applications can use WorldGate through ChatOpenAI's custom base URL support while selecting a listed GPT or Claude model. The integration is straightforward, but production chains need explicit timeouts, bounded retries, output limits, key isolation, and observability because one user action can trigger several model calls.

Create an account
01

Install the provider integration

Use the separate langchain-openai package and pin compatible LangChain package versions. Provider integrations evolve independently from LangChain core, so test upgrades against your chains and agents.

02

Configure ChatOpenAI for WorldGate

Pass the WorldGate key and https://worldgateapi.com/v1 base URL to ChatOpenAI. Keep both in server configuration and choose a model identifier returned by the current WorldGate catalogue.

03

Count chain calls, not only user actions

A retriever, router, tool loop, evaluator, or agent may make multiple model requests for one visible action. Measure final task cost and request count rather than assuming one chain invocation equals one billed completion.

04

Bound retries and output

Set an application timeout, limited retry count, and practical max_tokens value. Unlimited orchestration with automatic retries can turn a single malformed task into repeated spend.

05

Stream through the full chain

Use LangChain streaming only when every component and client transport handles incremental events and cancellation. Define what the product does with partial output when a tool or downstream step fails.

06

Separate environments and agents

Create distinct WorldGate keys for development, production, and autonomous agents. Add a hard cap when a chain needs a strict ceiling, enable balance alerts, and inspect request-level usage when projected spend changes.

LANGCHAIN SETUP

Use a custom base URL with bounded retries.

Measure every underlying model request generated by a chain or agent, not only the visible user action.

import os
from langchain_openai import ChatOpenAI

model = ChatOpenAI(
    model="claude-sonnet-5",
    api_key=os.environ["WORLDGATE_API_KEY"],
    base_url="https://worldgateapi.com/v1",
    timeout=60,
    max_retries=2,
)

response = model.invoke("Summarize this deployment plan.")
print(response.content)

METHODOLOGY & SOURCES

Review the LangChain integration.

LangChain configuration reviewed for WorldGate's OpenAI-compatible surface on July 31, 2026. Pin and test the package versions used by your application.

COMMON QUESTIONS

What developers ask

Can LangChain use a custom OpenAI-compatible endpoint?

Yes. ChatOpenAI accepts a custom base URL for compatible providers such as WorldGate.

Can ChatOpenAI select a Claude model?

Yes through WorldGate when the Claude identifier is currently listed and the chain uses supported compatible fields.

Which base URL should LangChain use?

Use https://worldgateapi.com/v1 with ChatOpenAI.

Why does one chain use several API requests?

Routers, tools, agents, retries, and evaluators can each call a model. Track request count and total task cost.

How do I stop a runaway LangChain agent?

Set bounded iterations and retries in the agent, use practical output limits, assign a dedicated key, and configure a hard cap when a strict spend ceiling is required.

Lower model cost. Clearer usage.

Start with one WorldGate API key.

Start building