Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-lemons-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ai-sdk/gateway": patch
---

Add the `caching: 'auto'` gateway provider option to the exported type schema.
6 changes: 6 additions & 0 deletions content/providers/01-ai-sdk-providers/00-ai-gateway.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,12 @@ The following gateway provider options are available:

Example: `models: ['openai/gpt-5.4-nano', 'gemini-3-flash-preview']` will try the fallback models in order if the primary model fails.

- **caching** _'auto'_

Enables automatic prompt caching for supported models.

Example: `caching: 'auto'` lets AI Gateway apply automatic prompt caching when the routed model supports it.

- **user** _string_

Optional identifier for the end user on whose behalf the request is being made. This is used for spend tracking and attribution purposes, allowing you to track usage per end-user in your application.
Expand Down
20 changes: 20 additions & 0 deletions packages/gateway/src/gateway-language-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,26 @@ describe('GatewayLanguageModel', () => {
});
});

it('should pass automatic caching option', async () => {
prepareJsonResponse({
content: { type: 'text', text: 'Test response' },
});

await createTestModel().doGenerate({
prompt: TEST_PROMPT,
providerOptions: {
gateway: {
caching: 'auto',
},
},
});

const requestBody = await server.calls[0].requestBodyJson;
expect(requestBody.providerOptions).toEqual({
gateway: { caching: 'auto' },
});
});

it('should pass providerTimeouts for doGenerate', async () => {
prepareJsonResponse({
content: { type: 'text', text: 'Test response' },
Expand Down
12 changes: 12 additions & 0 deletions packages/gateway/src/gateway-provider-options.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expectTypeOf, it } from 'vitest';
import type { GatewayProviderOptions } from './gateway-provider-options';

describe('GatewayProviderOptions type', () => {
it('should allow automatic caching', () => {
const options = {
caching: 'auto',
} satisfies GatewayProviderOptions;

expectTypeOf(options).toMatchTypeOf<GatewayProviderOptions>();
});
});
4 changes: 4 additions & 0 deletions packages/gateway/src/gateway-provider-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const gatewayProviderOptions = lazySchema(() =>
* Example: `['openai/gpt-5-nano', 'zai/glm-4.6']` will try `openai/gpt-5-nano` first, then `zai/glm-4.6` as fallback.
*/
models: z.array(z.string()).optional(),
/**
* Enable automatic prompt caching for supported models.
*/
caching: z.literal('auto').optional(),
/**
* Request-scoped BYOK credentials to use instead of cached credentials.
*
Expand Down