LangChain
LangChain gives you tools for every step of the agent development lifecycle. This guide demonstrates how to integrate Vercel AI Gateway with LangChain to access various AI models and providers.
First, create a new directory for your project and initialize it:
Install the required LangChain packages along with the and packages:
Create a file with your Vercel AI Gateway API key:
If you're using the AI Gateway from within a Vercel deployment, you can also use the environment variable which will be automatically provided.
Create a new file called with the following code:
The following code:
- Initializes a instance configured to use the AI Gateway
- Sets the model to
- Makes a chat completion request
- Handles any potential errors
Run your application using Node.js:
You should see a response from the AI model in your console.
Was this helpful?