Node.js
Official Portkey Node.js SDK – robust, modern, and fully typed integration for JavaScript and TypeScript developers.
The official Node.js SDK makes it easy to integrate Portkey’s AI gateway into any Node.js or TypeScript application. Enjoy unified access to 250+ LLMs, advanced observability, routing, governance, and enterprise features with just a few lines of code.
Installation
Install the Portkey SDK from npm:
API Key Setup
- Create a Portkey API key in your dashboard.
- Store your API key securely as an environment variable:
The SDK automatically detects your API key from the environment.
Quickstart
Here’s a minimal example to get you started:
You can use either a Virtual Key or a Config object to select your AI provider. Find more info on different authentication mechanisms here.
Authentication & Configuration
The SDK requires:
- Portkey API Key: Your Portkey API key (env var
PORTKEY_API_KEY
recommended) - Provider Authentication:
- Virtual Key: The Virtual Key of your chosen AI provider
- Config: The Config object or config slug for advanced routing
- Provider Slug + Auth Headers: Useful if you do not want to save your API keys to Portkey and make direct requests.
Adding Trace ID & Metadata
TypeScript Support
Portkey’s Node.js SDK is fully typed and works seamlessly with TypeScript:
Parameters
List of All Headers
View the complete list of headers that can be used with Portkey API requests, including authentication, configuration, and custom headers.
Here’s how you can use these headers with the Node.js SDK:
Troubleshooting & Support
- Having trouble? Email support or book a demo with our team.
- View the SDK on GitHub
- Report issues or request features