@ai-sdk/gateway 3.0.99 → 3.0.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +17 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -2
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +153 -139
- package/package.json +1 -1
- package/src/gateway-fetch-metadata.ts +45 -35
- package/src/gateway-model-entry.ts +11 -1
- package/src/gateway-provider-options.ts +8 -0
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
import { z } from 'zod/v4';
|
|
10
10
|
import { asGatewayError } from './errors';
|
|
11
11
|
import type { GatewayConfig } from './gateway-config';
|
|
12
|
-
import
|
|
12
|
+
import {
|
|
13
|
+
KNOWN_MODEL_TYPES,
|
|
14
|
+
type GatewayLanguageModelEntry,
|
|
15
|
+
type KnownModelType,
|
|
16
|
+
} from './gateway-model-entry';
|
|
13
17
|
|
|
14
18
|
type GatewayFetchMetadataConfig = GatewayConfig;
|
|
15
19
|
|
|
@@ -75,41 +79,47 @@ export class GatewayFetchMetadata {
|
|
|
75
79
|
const gatewayAvailableModelsResponseSchema = lazySchema(() =>
|
|
76
80
|
zodSchema(
|
|
77
81
|
z.object({
|
|
78
|
-
models: z
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(
|
|
92
|
-
input,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
82
|
+
models: z
|
|
83
|
+
.array(
|
|
84
|
+
z.object({
|
|
85
|
+
id: z.string(),
|
|
86
|
+
name: z.string(),
|
|
87
|
+
description: z.string().nullish(),
|
|
88
|
+
pricing: z
|
|
89
|
+
.object({
|
|
90
|
+
input: z.string(),
|
|
91
|
+
output: z.string(),
|
|
92
|
+
input_cache_read: z.string().nullish(),
|
|
93
|
+
input_cache_write: z.string().nullish(),
|
|
94
|
+
})
|
|
95
|
+
.transform(
|
|
96
|
+
({ input, output, input_cache_read, input_cache_write }) => ({
|
|
97
|
+
input,
|
|
98
|
+
output,
|
|
99
|
+
...(input_cache_read
|
|
100
|
+
? { cachedInputTokens: input_cache_read }
|
|
101
|
+
: {}),
|
|
102
|
+
...(input_cache_write
|
|
103
|
+
? { cacheCreationInputTokens: input_cache_write }
|
|
104
|
+
: {}),
|
|
105
|
+
}),
|
|
106
|
+
)
|
|
107
|
+
.nullish(),
|
|
108
|
+
specification: z.object({
|
|
109
|
+
specificationVersion: z.literal('v3'),
|
|
110
|
+
provider: z.string(),
|
|
111
|
+
modelId: z.string(),
|
|
112
|
+
}),
|
|
113
|
+
modelType: z.string().nullish(),
|
|
107
114
|
}),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
)
|
|
116
|
+
.transform(models =>
|
|
117
|
+
models.filter(
|
|
118
|
+
(m): m is typeof m & { modelType?: KnownModelType | null } =>
|
|
119
|
+
m.modelType == null ||
|
|
120
|
+
KNOWN_MODEL_TYPES.includes(m.modelType as KnownModelType),
|
|
121
|
+
),
|
|
122
|
+
),
|
|
113
123
|
}),
|
|
114
124
|
),
|
|
115
125
|
);
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
|
+
export const KNOWN_MODEL_TYPES = [
|
|
4
|
+
'embedding',
|
|
5
|
+
'image',
|
|
6
|
+
'language',
|
|
7
|
+
'reranking',
|
|
8
|
+
'video',
|
|
9
|
+
] as const;
|
|
10
|
+
|
|
11
|
+
export type KnownModelType = (typeof KNOWN_MODEL_TYPES)[number];
|
|
12
|
+
|
|
3
13
|
export interface GatewayLanguageModelEntry {
|
|
4
14
|
/**
|
|
5
15
|
* The model id used by the remote provider in model settings and for specifying the
|
|
@@ -49,7 +59,7 @@ export interface GatewayLanguageModelEntry {
|
|
|
49
59
|
/**
|
|
50
60
|
* Optional field to differentiate between model types.
|
|
51
61
|
*/
|
|
52
|
-
modelType?:
|
|
62
|
+
modelType?: KnownModelType | null;
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
export type GatewayLanguageModelSpecification = Pick<
|
|
@@ -17,6 +17,14 @@ const gatewayProviderOptions = lazySchema(() =>
|
|
|
17
17
|
* Example: `['bedrock', 'anthropic']` will try Amazon Bedrock first, then Anthropic as fallback.
|
|
18
18
|
*/
|
|
19
19
|
order: z.array(z.string()).optional(),
|
|
20
|
+
/**
|
|
21
|
+
* Sort providers by a performance or cost metric before routing.
|
|
22
|
+
*
|
|
23
|
+
* - `'cost'`: lowest cost first
|
|
24
|
+
* - `'ttft'`: lowest time-to-first-token first
|
|
25
|
+
* - `'tps'`: highest tokens-per-second first
|
|
26
|
+
*/
|
|
27
|
+
sort: z.enum(['cost', 'ttft', 'tps']).optional(),
|
|
20
28
|
/**
|
|
21
29
|
* The unique identifier for the end user on behalf of whom the request was made.
|
|
22
30
|
*
|