Skip to content

Commit f24fac7

Browse files
Remove @openrouter/sdk dependency (#357)
- Create src/types/openrouter-api-types.ts with locally defined types - Update error-response.ts to import ChatErrorError from local types - Update openrouter-chat-settings.ts to import all enum types from local types - Remove @openrouter/sdk from package.json dependencies The types are now defined locally to reduce dependency footprint and eliminate potential version conflicts with the SDK. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 33c0e03 commit f24fac7

File tree

6 files changed

+100
-27
lines changed

6 files changed

+100
-27
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@openrouter/ai-sdk-provider": minor
3+
---
4+
5+
Remove dependency on @openrouter/sdk
6+
7+
This change removes the external dependency on `@openrouter/sdk` by inlining the necessary type definitions locally. The types are now defined in `src/types/openrouter-api-types.ts`.
8+
9+
This reduces the package's dependency footprint and eliminates potential version conflicts with the SDK.
10+

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,5 @@
8484
"keywords": [
8585
"ai"
8686
],
87-
"packageManager": "pnpm@10.12.4",
88-
"dependencies": {
89-
"@openrouter/sdk": "^0.1.27"
90-
}
87+
"packageManager": "pnpm@10.12.4"
9188
}

pnpm-lock.yaml

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/schemas/error-response.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import type { ChatErrorError } from '@openrouter/sdk/models';
1+
import type { ChatErrorError } from '../types/openrouter-api-types';
22

33
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
44
import { z } from 'zod/v4';
55

6-
// Use SDK's ChatErrorError type but wrap in response schema
7-
// SDK type: { code: string | number | null; message: string; param?: string | null; type?: string | null }
86
export const OpenRouterErrorResponseSchema = z
97
.object({
108
error: z

src/types/openrouter-api-types.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* OpenRouter API types - locally defined to avoid external SDK dependency.
3+
* These types mirror the OpenRouter API specification.
4+
*/
5+
6+
/**
7+
* Error structure returned by OpenRouter API.
8+
*/
9+
export type ChatErrorError = {
10+
code: string | number | null;
11+
message: string;
12+
param?: string | null | undefined;
13+
type?: string | null | undefined;
14+
};
15+
16+
/**
17+
* Plugin identifier for web search functionality.
18+
*/
19+
export type IdWeb = 'web';
20+
21+
/**
22+
* Plugin identifier for file parsing functionality.
23+
*/
24+
export type IdFileParser = 'file-parser';
25+
26+
/**
27+
* Plugin identifier for content moderation.
28+
*/
29+
export type IdModeration = 'moderation';
30+
31+
/**
32+
* Search engine options for web search.
33+
* Open enum - accepts known values or any string for forward compatibility.
34+
*/
35+
export type Engine = 'native' | 'exa' | (string & {});
36+
37+
/**
38+
* PDF processing engine options.
39+
* Open enum - accepts known values or any string for forward compatibility.
40+
*/
41+
export type PdfEngine = 'mistral-ocr' | 'pdf-text' | 'native' | (string & {});
42+
43+
/**
44+
* Data collection preference for provider routing.
45+
* Open enum - accepts known values or any string for forward compatibility.
46+
*/
47+
export type DataCollection = 'deny' | 'allow' | (string & {});
48+
49+
/**
50+
* Model quantization levels for provider filtering.
51+
* Open enum - accepts known values or any string for forward compatibility.
52+
*/
53+
export type Quantization =
54+
| 'int4'
55+
| 'int8'
56+
| 'fp4'
57+
| 'fp6'
58+
| 'fp8'
59+
| 'fp16'
60+
| 'bf16'
61+
| 'fp32'
62+
| 'unknown'
63+
| (string & {});
64+
65+
/**
66+
* Provider sorting strategy options.
67+
* Open enum - accepts known values or any string for forward compatibility.
68+
*/
69+
export type ProviderSort = 'price' | 'throughput' | 'latency' | (string & {});

src/types/openrouter-chat-settings.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import type * as models from '@openrouter/sdk/models';
21
import type { OpenRouterSharedSettings } from '..';
2+
import type {
3+
DataCollection,
4+
Engine,
5+
IdFileParser,
6+
IdModeration,
7+
IdWeb,
8+
PdfEngine,
9+
ProviderSort,
10+
Quantization,
11+
} from './openrouter-api-types';
312

413
// https://openrouter.ai/api/v1/models
514
export type OpenRouterChatModelId = string;
@@ -50,20 +59,20 @@ monitor and detect abuse. Learn more.
5059
*/
5160
plugins?: Array<
5261
| {
53-
id: models.IdWeb;
62+
id: IdWeb;
5463
max_results?: number;
5564
search_prompt?: string;
56-
engine?: models.Engine;
65+
engine?: Engine;
5766
}
5867
| {
59-
id: models.IdFileParser;
68+
id: IdFileParser;
6069
max_files?: number;
6170
pdf?: {
62-
engine?: models.PdfEngine;
71+
engine?: PdfEngine;
6372
};
6473
}
6574
| {
66-
id: models.IdModeration;
75+
id: IdModeration;
6776
}
6877
>;
6978

@@ -86,7 +95,7 @@ monitor and detect abuse. Learn more.
8695
* - undefined: Native if supported, otherwise Exa
8796
* @see https://openrouter.ai/docs/features/web-search
8897
*/
89-
engine?: models.Engine;
98+
engine?: Engine;
9099
};
91100

92101
/**
@@ -122,7 +131,7 @@ monitor and detect abuse. Learn more.
122131
/**
123132
* Control whether to use providers that may store data
124133
*/
125-
data_collection?: models.DataCollection;
134+
data_collection?: DataCollection;
126135
/**
127136
* List of provider slugs to allow for this request
128137
*/
@@ -134,11 +143,11 @@ monitor and detect abuse. Learn more.
134143
/**
135144
* List of quantization levels to filter by (e.g. ["int4", "int8"])
136145
*/
137-
quantizations?: Array<models.Quantization>;
146+
quantizations?: Array<Quantization>;
138147
/**
139148
* Sort providers by price, throughput, or latency
140149
*/
141-
sort?: models.ProviderSort;
150+
sort?: ProviderSort;
142151
/**
143152
* Maximum pricing you want to pay for this request
144153
*/

0 commit comments

Comments
 (0)