Skip to content

Commit 4118f46

Browse files
committed
add env vars
1 parent dffeb56 commit 4118f46

File tree

5 files changed

+97
-50
lines changed

5 files changed

+97
-50
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OpenRouter API Key for running E2E tests
2+
# Get your API key from https://openrouter.ai/keys
3+
OPENROUTER_API_KEY=your_api_key_here

.github/actions/validate-sdk/action.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ runs:
4444

4545
- name: Run tests
4646
shell: bash
47+
env:
48+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
4749
run: npx vitest

.github/workflows/validation-checks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ jobs:
1212

1313
- name: Validate SDK
1414
uses: ./.github/actions/validate-sdk
15+
with:
16+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}

README.md

Lines changed: 77 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ This SDK supports the following security scheme globally:
216216
| `apiKey` | http | HTTP Bearer | `OPENROUTER_API_KEY` |
217217

218218
To authenticate with the API the `apiKey` parameter must be set when initializing the SDK client instance. For example:
219+
219220
```typescript
220221
import { OpenRouter } from "@openrouter/sdk";
221222

@@ -344,6 +345,7 @@ run();
344345
### Per-Operation Security Schemes
345346

346347
Some operations in this SDK require the security scheme to be specified at the request level. For example:
348+
347349
```typescript
348350
import { OpenRouter } from "@openrouter/sdk";
349351

@@ -448,28 +450,28 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md).
448450

449451
<summary>Available standalone functions</summary>
450452

451-
- [`analyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
452-
- [`apiKeysCreate`](docs/sdks/apikeys/README.md#create) - Create a new API key
453-
- [`apiKeysDelete`](docs/sdks/apikeys/README.md#delete) - Delete an API key
454-
- [`apiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
455-
- [`apiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
456-
- [`apiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
457-
- [`apiKeysUpdate`](docs/sdks/apikeys/README.md#update) - Update an API key
458-
- [`betaResponsesSend`](docs/sdks/responses/README.md#send) - Create a response
459-
- [`chatSend`](docs/sdks/chat/README.md#send) - Create a chat completion
460-
- [`completionsGenerate`](docs/sdks/completions/README.md#generate) - Create a completion
461-
- [`creditsCreateCoinbaseCharge`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
462-
- [`creditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
463-
- [`endpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
464-
- [`endpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
465-
- [`generationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
466-
- [`modelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
467-
- [`modelsList`](docs/sdks/models/README.md#list) - List all models and their properties
468-
- [`modelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
469-
- [`oAuthCreateAuthCode`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
470-
- [`oAuthExchangeAuthCodeForAPIKey`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
471-
- [`parametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
472-
- [`providersList`](docs/sdks/providers/README.md#list) - List all providers
453+
* [`analyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
454+
* [`apiKeysCreate`](docs/sdks/apikeys/README.md#create) - Create a new API key
455+
* [`apiKeysDelete`](docs/sdks/apikeys/README.md#delete) - Delete an API key
456+
* [`apiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
457+
* [`apiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
458+
* [`apiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
459+
* [`apiKeysUpdate`](docs/sdks/apikeys/README.md#update) - Update an API key
460+
* [`betaResponsesSend`](docs/sdks/responses/README.md#send) - Create a response
461+
* [`chatSend`](docs/sdks/chat/README.md#send) - Create a chat completion
462+
* [`completionsGenerate`](docs/sdks/completions/README.md#generate) - Create a completion
463+
* [`creditsCreateCoinbaseCharge`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
464+
* [`creditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
465+
* [`endpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
466+
* [`endpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
467+
* [`generationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
468+
* [`modelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
469+
* [`modelsList`](docs/sdks/models/README.md#list) - List all models and their properties
470+
* [`modelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
471+
* [`oAuthCreateAuthCode`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
472+
* [`oAuthExchangeAuthCodeForAPIKey`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
473+
* [`parametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
474+
* [`providersList`](docs/sdks/providers/README.md#list) - List all providers
473475

474476
</details>
475477
<!-- End Standalone functions [standalone-funcs] -->
@@ -496,28 +498,28 @@ To learn about this feature and how to get started, check
496498

497499
<summary>Available React hooks</summary>
498500

499-
- [`useAnalyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
500-
- [`useApiKeysCreateMutation`](docs/sdks/apikeys/README.md#create) - Create a new API key
501-
- [`useApiKeysDeleteMutation`](docs/sdks/apikeys/README.md#delete) - Delete an API key
502-
- [`useApiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
503-
- [`useApiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
504-
- [`useApiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
505-
- [`useApiKeysUpdateMutation`](docs/sdks/apikeys/README.md#update) - Update an API key
506-
- [`useBetaResponsesSendMutation`](docs/sdks/responses/README.md#send) - Create a response
507-
- [`useChatSendMutation`](docs/sdks/chat/README.md#send) - Create a chat completion
508-
- [`useCompletionsGenerateMutation`](docs/sdks/completions/README.md#generate) - Create a completion
509-
- [`useCreditsCreateCoinbaseChargeMutation`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
510-
- [`useCreditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
511-
- [`useEndpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
512-
- [`useEndpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
513-
- [`useGenerationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
514-
- [`useModelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
515-
- [`useModelsList`](docs/sdks/models/README.md#list) - List all models and their properties
516-
- [`useModelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
517-
- [`useOAuthCreateAuthCodeMutation`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
518-
- [`useOAuthExchangeAuthCodeForAPIKeyMutation`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
519-
- [`useParametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
520-
- [`useProvidersList`](docs/sdks/providers/README.md#list) - List all providers
501+
* [`useAnalyticsGetUserActivity`](docs/sdks/analytics/README.md#getuseractivity) - Get user activity grouped by endpoint
502+
* [`useApiKeysCreateMutation`](docs/sdks/apikeys/README.md#create) - Create a new API key
503+
* [`useApiKeysDeleteMutation`](docs/sdks/apikeys/README.md#delete) - Delete an API key
504+
* [`useApiKeysGet`](docs/sdks/apikeys/README.md#get) - Get a single API key
505+
* [`useApiKeysGetCurrentKeyMetadata`](docs/sdks/apikeys/README.md#getcurrentkeymetadata) - Get current API key
506+
* [`useApiKeysList`](docs/sdks/apikeys/README.md#list) - List API keys
507+
* [`useApiKeysUpdateMutation`](docs/sdks/apikeys/README.md#update) - Update an API key
508+
* [`useBetaResponsesSendMutation`](docs/sdks/responses/README.md#send) - Create a response
509+
* [`useChatSendMutation`](docs/sdks/chat/README.md#send) - Create a chat completion
510+
* [`useCompletionsGenerateMutation`](docs/sdks/completions/README.md#generate) - Create a completion
511+
* [`useCreditsCreateCoinbaseChargeMutation`](docs/sdks/credits/README.md#createcoinbasecharge) - Create a Coinbase charge for crypto payment
512+
* [`useCreditsGetCredits`](docs/sdks/credits/README.md#getcredits) - Get remaining credits
513+
* [`useEndpointsList`](docs/sdks/endpoints/README.md#list) - List all endpoints for a model
514+
* [`useEndpointsListZdrEndpoints`](docs/sdks/endpoints/README.md#listzdrendpoints) - Preview the impact of ZDR on the available endpoints
515+
* [`useGenerationsGetGeneration`](docs/sdks/generations/README.md#getgeneration) - Get request & usage metadata for a generation
516+
* [`useModelsCount`](docs/sdks/models/README.md#count) - Get total count of available models
517+
* [`useModelsList`](docs/sdks/models/README.md#list) - List all models and their properties
518+
* [`useModelsListForUser`](docs/sdks/models/README.md#listforuser) - List models filtered by user provider preferences
519+
* [`useOAuthCreateAuthCodeMutation`](docs/sdks/oauth/README.md#createauthcode) - Create authorization code
520+
* [`useOAuthExchangeAuthCodeForAPIKeyMutation`](docs/sdks/oauth/README.md#exchangeauthcodeforapikey) - Exchange authorization code for API key
521+
* [`useParametersGetParameters`](docs/sdks/parameters/README.md#getparameters) - Get a model's supported parameters and data about which are most popular
522+
* [`useProvidersList`](docs/sdks/providers/README.md#list) - List all providers
521523

522524
</details>
523525
<!-- End React hooks with TanStack Query [react-query] -->
@@ -666,6 +668,7 @@ run();
666668
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
667669

668670
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
671+
669672
```typescript
670673
import { OpenRouter } from "@openrouter/sdk";
671674

@@ -803,6 +806,7 @@ run();
803806
```
804807

805808
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
809+
806810
```typescript
807811
import { OpenRouter } from "@openrouter/sdk";
808812

@@ -954,6 +958,7 @@ run();
954958
| `error.data$` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |
955959

956960
### Example
961+
957962
```typescript
958963
import { OpenRouter } from "@openrouter/sdk";
959964
import * as errors from "@openrouter/sdk/models/errors";
@@ -1097,7 +1102,9 @@ run();
10971102
```
10981103

10991104
### Error Classes
1105+
11001106
**Primary errors:**
1107+
11011108
* [`OpenRouterError`](./src/models/errors/openroutererror.ts): The base class for HTTP error responses.
11021109
* [`InternalServerResponseError`](./src/models/errors/internalserverresponseerror.ts): Internal Server Error - Unexpected server error. Status code `500`. *
11031110

@@ -1106,14 +1113,15 @@ run();
11061113
<br />
11071114

11081115
**Network errors:**
1116+
11091117
* [`ConnectionError`](./src/models/errors/httpclienterrors.ts): HTTP client was unable to make a request to a server.
11101118
* [`RequestTimeoutError`](./src/models/errors/httpclienterrors.ts): HTTP request timed out due to an AbortSignal signal.
11111119
* [`RequestAbortedError`](./src/models/errors/httpclienterrors.ts): HTTP request was aborted by the client.
11121120
* [`InvalidRequestError`](./src/models/errors/httpclienterrors.ts): Any input used to create a request is invalid.
11131121
* [`UnexpectedClientError`](./src/models/errors/httpclienterrors.ts): Unrecognised or unexpected error.
11141122

1115-
11161123
**Inherit from [`OpenRouterError`](./src/models/errors/openroutererror.ts)**:
1124+
11171125
* [`UnauthorizedResponseError`](./src/models/errors/unauthorizedresponseerror.ts): Unauthorized - Authentication required or invalid credentials. Status code `401`. Applicable to 14 of 22 methods.*
11181126
* [`BadRequestResponseError`](./src/models/errors/badrequestresponseerror.ts): Bad Request - Invalid request parameters or malformed input. Status code `400`. Applicable to 8 of 22 methods.*
11191127
* [`TooManyRequestsResponseError`](./src/models/errors/toomanyrequestsresponseerror.ts): Too Many Requests - Rate limit exceeded. Status code `429`. Applicable to 8 of 22 methods.*
@@ -1162,6 +1170,30 @@ You can also enable a default debug logger by setting an environment variable `O
11621170

11631171
# Development
11641172

1173+
## Running Tests
1174+
1175+
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
1176+
1177+
### Local Development
1178+
1179+
1. Copy the example environment file:
1180+
1181+
```bash
1182+
cp .env.example .env
1183+
```
1184+
1185+
2. Edit `.env` and add your OpenRouter API key:
1186+
1187+
```bash
1188+
OPENROUTER_API_KEY=your_api_key_here
1189+
```
1190+
1191+
3. Run the tests:
1192+
1193+
```bash
1194+
npx vitest
1195+
```
1196+
11651197
## Maturity
11661198

11671199
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage

vitest.config.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import { config } from "dotenv";
22
import { defineConfig } from "vitest/config";
3+
import { fileURLToPath } from "url";
4+
import { dirname, join } from "path";
35

4-
// Load environment variables from .env file
5-
config();
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
// Load environment variables from .env file if it exists
10+
// This will not override existing environment variables
11+
config({ path: join(__dirname, ".env") });
612

713
export default defineConfig({
814
test: {
915
globals: true,
1016
environment: "node",
11-
env: {
12-
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY || "",
13-
},
17+
// Don't override env vars - just let them pass through from the system
18+
// The env object here will be merged with process.env
19+
env: process.env.OPENROUTER_API_KEY ? {
20+
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
21+
} : {},
1422
include: ["tests/**/*.test.ts"],
1523
hookTimeout: 30000,
1624
testTimeout: 30000,

0 commit comments

Comments
 (0)