Skip to content

feat: add service_tier to openai langchain chat #8329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SamuelScheit
Copy link

OpenAI introduced Flex processing which

provides significantly lower costs for Chat Completions or Responses requests in exchange for slower response times and occasional resource unavailability. It is ideal for non-production or lower-priority tasks such as model evaluations, data enrichment, or asynchronous workloads.

The python counterpart already has the ability to specify a service_tier but the JS library is missing it, which this PR adds

Example

const llm = new ChatOpenAI({
	model: "o4-mini",
	apiKey: process.env.OPENAI_API_KEY,
	service_tier: "flex",
	timeout: 60 * 1000 * 30,
});

llm.invoke("Hi", {
	service_tier: "default", // service_tier can be overridden when invoking llm
});

Keep in mind that:

Flex processing is in beta, and currently only available for o3 and o4-mini models.

Copy link

vercel bot commented Jun 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jun 8, 2025 0:35am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jun 8, 2025 0:35am

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant