2027 setup guide · Agent frameworks

LangChain with an OpenAI-compatible API

ChatOpenAI will talk to many compatible endpoints, but LangChain's own docs say it preserves the official OpenAI shape only. Extended provider fields are where integrations break.

Abstract illustration of a Python framework connected to model APIs
Illustration: a framework calling a compatible chat model. Plugsky Editorial Team.

LangChain is a framework, not a model provider. Its ChatOpenAI class is the default way Python applications reach OpenAI-shaped chat APIs, and it accepts a base_url, so the same class can point at a gateway or a private endpoint. That is the shortest path from a LangChain prototype to a different provider: change the base URL and the model name, keep the rest of the chain.

The shortcut has a documented boundary. LangChain's ChatOpenAI integration targets the official OpenAI API specification. Non-standard response fields from third-party providers, such as reasoning_content, are not extracted or preserved, and the docs recommend a provider-specific package for services that extend the format. A compatible endpoint that only implements the standard shape is fine. One that adds its own reasoning or citation fields needs more care.

ChatOpenAI compatibility checks, checked 23 November 2026
ConcernWhat ChatOpenAI doesWhat to do
Base URLAccepts base_url, OPENAI_API_BASE or OPENAI_BASE_URLSet one explicitly; do not rely on an inherited environment variable.
Streaming usageLeaves stream_usage off by default when a non-OpenAI base URL is setEnable it only if the endpoint returns usage in streamed responses.
Tool callingPasses OpenAI-shaped toolsTest the model, not just the endpoint; tool support varies by model.
Structured outputUses OpenAI response formatsVerify the endpoint honours the schema rather than returning prose.
Non-standard fieldsNot extracted or preservedUse a provider-specific package if reasoning or citation fields matter.
Async and batchingSupported by the clientCheck rate limits and retry behaviour at the gateway, not only in the app.

The minimal ChatOpenAI setup

Install the integration package, then create a ChatOpenAI with three values: the model ID, the base URL and the API key. For Plugsky the base URL is https://api.plugsky.com/v1 and the key is a Plugsky key. The model ID must be one the endpoint publishes; LangChain sends the ID you configure.

Keep the key in an environment variable or a secret manager rather than in the source. LangChain reads OPENAI_API_KEY by default, which is convenient for a local test and risky in a shared environment: a developer who exports an OpenAI key can silently send requests to the wrong provider. Set the key explicitly on the client when the endpoint is not OpenAI.

A minimal setup is enough for a chat prompt, a retriever chain and a tool-calling agent that uses the standard OpenAI tool schema. It is not enough for every provider-specific feature, and the next section explains why.

  • Package: langchain-openai
  • Class: ChatOpenAI
  • model: a published model ID
  • base_url: https://api.plugsky.com/v1
  • api_key: an explicit key, not an inherited OpenAI key

The compatibility boundary in LangChain's docs

LangChain's ChatOpenAI page states that the class targets official OpenAI API specifications only. Non-standard response fields from third-party providers, including reasoning_content, reasoning and reasoning_details, are not extracted or preserved. The docs name OpenRouter, LiteLLM, vLLM and DeepSeek as examples of providers that extend the format and recommend a provider-specific package for them.

That does not mean those providers fail. It means a chain that depends on an extended field will see it disappear. A reasoning trace, a citation list or a provider-specific finish reason may be in the raw response and absent from the LangChain object. If your evaluation or logging depends on that field, test the object, not the HTTP response.

The practical rule: use ChatOpenAI when the endpoint implements the standard chat completions or responses shape and you only need standard fields. Use a provider-specific integration when the value is in the extension.

Base URL resolution and streaming usage

LangChain resolves the base URL in a documented order: an explicit base_url or openai_api_base argument first, then OPENAI_API_BASE, then OPENAI_BASE_URL read by the underlying OpenAI SDK. The order matters in a monorepo where one service sets an environment variable for another. Pass the value explicitly and the ambiguity disappears.

Streaming usage has a related default. LangChain inspects OPENAI_BASE_URL and, when it is set, leaves stream_usage off by default because many non-OpenAI endpoints do not support streaming token usage. If your endpoint does return usage in the stream, enable it deliberately and verify the numbers against the gateway's record.

Token counts are a billing concern, not a cosmetic one. A chain that reports zero usage because the flag was off will make cost dashboards wrong even when the requests succeed.

What to check before production

Test the four features your chain actually uses: tool calling, structured output, image input and async invocation. Each depends on the model as much as the endpoint. A model that handles chat well can fail a JSON schema or emit a tool call in the wrong shape.

Test a failure. Point the client at a model that does not exist and confirm that the error surfaces with the provider's message rather than a generic timeout. Then test a rate limit and confirm that LangChain's retry settings and the gateway's limits do not multiply into a retry storm. A small contract test that asserts the shape of a tool call catches more than a benchmark.

Finally, pin the package version. Compatibility is a moving target on both sides: the integration package changes, and so does the endpoint. A lockfile and a small contract test are cheaper than discovering a behavioural change in production.

LangChain's tracing and callback hooks see the LangChain object, not the raw HTTP response. If the gateway returns a field that ChatOpenAI drops, a callback will not recover it. Use gateway logs for wire-level evidence and LangChain tracing for application-level traces.

When a competitor wins

A provider-specific LangChain package wins when you need the provider's extended fields or first-class support for its reasoning controls. The OpenAI SDK directly wins when the application is small and the framework adds more surface than value. LiteLLM wins when the requirement is a proxy that normalises many providers behind one OpenAI-shaped API.

Plugsky wins when the application is standard OpenAI-shaped, the team wants a flat monthly plan and the same endpoint has to move from shared API to private VPC or air-gapped deployment. The limit is the same one that applies to any compatible endpoint: 39 public model IDs, so confirm that the model you need supports the tools and structured output your chain relies on.

Verdict

Use ChatOpenAI with an explicit base_url, model ID and key. Enable stream_usage only if the endpoint supports it, and test tool calling, structured output and a failure path before production. If your chain depends on provider-specific response fields, switch to that provider's package.

Choose Plugsky when a standard OpenAI-shaped endpoint, a predictable monthly bill and a private deployment path are the priorities. Choose a provider-specific package or direct SDK when extended fields and vendor controls are part of the product.

Frequently asked questions

Can LangChain ChatOpenAI use a non-OpenAI endpoint?

Yes. ChatOpenAI accepts a base_url and will send OpenAI-shaped requests to any endpoint that implements them. The docs recommend a provider-specific package when the provider extends the response format.

Why is stream_usage off by default?

LangChain leaves it off when OPENAI_BASE_URL is set because many non-OpenAI endpoints do not support streaming token usage. Enable it only after confirming the endpoint returns usage in the stream.

Which base URL takes precedence?

An explicit base_url or openai_api_base argument wins, then OPENAI_API_BASE, then OPENAI_BASE_URL read by the OpenAI SDK.

Will reasoning_content be available?

LangChain's docs say non-standard fields such as reasoning_content are not extracted or preserved by ChatOpenAI. Use a provider-specific package if you need them.

Does ChatOpenAI support tool calling?

It passes OpenAI-shaped tools, but the model behind the endpoint must support them. Test the model with a real tool call rather than assuming endpoint compatibility is enough.

Related

Sources

  1. LangChain: ChatOpenAI integration · 23 Nov 2026
  2. LangChain documentation · 23 Nov 2026
  3. Plugsky API quickstart · 23 Nov 2026