Skip to content

Commit

Permalink
🎯 feat(config): Custom Endpoint Request Headers (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Jan 19, 2024
1 parent ab33392 commit 7e2e19a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions api/server/services/Endpoints/custom/initializeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const initializeClient = async ({ req, res, endpointOption }) => {
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);

let resolvedHeaders = {};
if (endpointConfig.headers && typeof endpointConfig.headers === 'object') {
Object.keys(endpointConfig.headers).forEach((key) => {
resolvedHeaders[key] = extractEnvVariable(endpointConfig.headers[key]);
});
}

if (CUSTOM_API_KEY.match(envVarRegex)) {
throw new Error(`Missing API Key for ${endpoint}.`);
}
Expand All @@ -31,6 +38,7 @@ const initializeClient = async ({ req, res, endpointOption }) => {
}

const customOptions = {
headers: resolvedHeaders,
addParams: endpointConfig.addParams,
dropParams: endpointConfig.dropParams,
titleConvo: endpointConfig.titleConvo,
Expand Down
15 changes: 15 additions & 0 deletions docs/install/configuration/custom_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ endpoints:
- **Description**: Excludes specified [default parameters](#default-parameters). Useful for APIs that do not accept or recognize certain parameters.
- **Example**: `dropParams: ["stop", "user", "frequency_penalty", "presence_penalty"]`
- **Note**: For a list of default parameters sent with every request, see the ["Default Parameters"](#default-parameters) Section below.

### **headers**:

> Adds additional headers to requests. Can reference an environment variable

- Type: Object/Dictionary
- **Description**: The `headers` object specifies custom headers for requests. Useful for authentication and setting content types.
- **Example**:
- **Note**: Supports dynamic environment variable values, which use the format: `"${VARIABLE_NAME}"`
```yaml
headers:
x-api-key: "${ENVIRONMENT_VARIABLE}"
Content-Type: "application/json"
```

## Additional Notes
- Ensure that all URLs and keys are correctly specified to avoid connectivity issues.

Expand Down
2 changes: 1 addition & 1 deletion packages/data-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librechat-data-provider",
"version": "0.3.6",
"version": "0.3.7",
"description": "data services for librechat apps",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const endpointSchema = z.object({
summaryModel: z.string().optional(),
forcePrompt: z.boolean().optional(),
modelDisplayLabel: z.string().optional(),
headers: z.record(z.any()).optional(),
});

export const configSchema = z.object({
Expand Down

0 comments on commit 7e2e19a

Please sign in to comment.