Skip to main content

Dealing with API Errors

If the model provider returns an error from their API, by default LangChain will retry up to 6 times on an exponential backoff. This enables error recovery without any additional effort from you. If you want to change this behavior, you can pass a maxRetries option when you instantiate the model. For example:

npm install @langchain/openai
import { OpenAI } from "@langchain/openai";

const model = new OpenAI({ maxRetries: 10 });

Help us out by providing feedback on this documentation page: