baseURL, the API key and the model id.
Overview
Point the OpenAI TypeScript SDK at Eden AI and it can call any of the 1000+ models.Installation
Install the OpenAI SDK for Node.js. The Environment Variables section below also usesdotenv, which you install the same way (npm install dotenv):
Quick Start
Configure the client to use Eden AI:Model naming
Use a model name or~ alias from GET /v3/models, such as ~claude-sonnet-latest; a provider/model id pins one provider.
Multi-Turn Conversations
Build stateful chat applications:Advanced Parameters
Control model behavior:Vision
Send an image as animage_url content part, the same shape the OpenAI API uses. The URL can be a public http(s) link or a base64 data URL:
data:image/jpeg;base64,....
Uploaded files
For documents such as PDFs, or to reuse one file across requests, upload it to/v3/upload and pass the returned file_id in a file content part. File Attachments covers file types, limits and expiry. This sample uses the fetch, FormData and Blob globals of Node 18 and later, so it needs no extra install:
Error Handling
The SDK retries 429 and 5xx responses twice by default (setmaxRetries on the client to change it), so the 429 branch below runs only after those retries are used up. The SDK has a dedicated error class for some statuses (401, 403, 429) but not for 402 or 451, so branch on error.status. Eden AI answers a failed request with these statuses:
- 400: the model id is unknown or inactive (
Model(s) not found or inactive). - 401: the key is invalid (
Invalid API keyorInvalid token) or has expired (Custom token has expired.). - 402: insufficient credits.
- 403: the account has no organization, a guardrail policy blocks the model, or your organization’s compliance policy requires zero data retention and no provider of the model qualifies.
- 422: the request body is invalid.
- 429: rate limit.
- 451: no provider of the model runs in a region that the endpoint you called, or your organization’s compliance policy, allows. It also answers when every target of a routing policy was dropped for region.
Environment Variables
Use.env files for configuration:
Next Steps
- Streaming Responses - Handle Server-Sent Events
- File Attachments - Working with images and documents
- Listing Models - Browse the model catalog