Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ef7b112
enabled built-in tools code_interpreter,file_search on Azure Response…
tsuzaki430 Aug 14, 2025
1f06809
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 14, 2025
9392e37
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 15, 2025
d248f7d
make changeset
tsuzaki430 Aug 15, 2025
3a54d82
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 16, 2025
99e1a07
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 19, 2025
d722639
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 21, 2025
558a887
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 23, 2025
d269ed4
document add file_search code_interpreter
tsuzaki430 Aug 23, 2025
40e43e2
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 26, 2025
69843d1
add test
tsuzaki430 Aug 27, 2025
78bbedd
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 27, 2025
06f0659
prettier-fix
tsuzaki430 Aug 27, 2025
bd8394a
Update packages/azure/src/azure-openai-provider.test.ts
tsuzaki430 Aug 27, 2025
e33c099
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 29, 2025
dfde373
fix changeset error
tsuzaki430 Aug 29, 2025
6473058
fix changeset 2
tsuzaki430 Aug 29, 2025
e3ac311
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 29, 2025
06e46d2
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Aug 30, 2025
a197d9b
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 5, 2025
8722bf4
add example for file search
tsuzaki430 Sep 8, 2025
17ff6c0
add example for code interpreter
tsuzaki430 Sep 8, 2025
0071e4b
add example for openai code interpreter
tsuzaki430 Sep 8, 2025
76a5ec3
Merge branch 'tsuz/azure-responsesapi-code-interpreter' of https://gi…
tsuzaki430 Sep 8, 2025
6aeaee1
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 8, 2025
3756af2
prettier-fix
tsuzaki430 Sep 8, 2025
71db155
add example for file search to compare openai vs azure
tsuzaki430 Sep 8, 2025
cad907a
add filesearch example for streamText
tsuzaki430 Sep 9, 2025
264de2d
small fix
tsuzaki430 Sep 9, 2025
c857ab9
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 11, 2025
de2118e
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 12, 2025
eac571c
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 12, 2025
cc03a32
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 15, 2025
ee7b359
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 16, 2025
a8a851b
Merge branch 'vercel:main' into tsuz/azure-responsesapi-code-interpreter
tsuzaki430 Sep 17, 2025
b1dd6d0
Merge remote-tracking branch 'upstream/main' into tsuz/azure-response…
tsuzaki430 Sep 25, 2025
f4b787e
merge
tsuzaki430 Sep 25, 2025
051a171
fix type error
tsuzaki430 Sep 26, 2025
5f40e14
add test azure file search in ai-core
tsuzaki430 Sep 26, 2025
ebff7ee
prettier-fix
tsuzaki430 Sep 26, 2025
f7ac746
Merge branch 'main' into tsuz/azure-responsesapi-code-interpreter
gr2m Sep 26, 2025
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
6 changes: 6 additions & 0 deletions .changeset/fruity-webs-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ai-sdk/openai': patch
'@ai-sdk/azure': patch
---

enables code_interpreter and file_search capabilities in the Azure provider through the Responses API
63 changes: 63 additions & 0 deletions content/providers/01-ai-sdk-providers/04-azure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,69 @@ The following OpenAI-specific metadata is returned:
- **reasoningTokens** _number_
The number of reasoning tokens that the model generated.

#### File Search

The Azure OpenAI responses API supports file search through the `azure.tools.fileSearch` tool.

You can force the use of the file search tool by setting the `toolChoice` parameter to `{ type: 'tool', toolName: 'file_search' }`.

```ts
const result = await generateText({
model: azure.responses('gpt-5'),
prompt: 'What does the document say about user authentication?',
tools: {
file_search: azure.tools.fileSearch({
// optional configuration:
vectorStoreIds: ['vs_123', 'vs_456'],
maxNumResults: 10,
ranking: {
ranker: 'auto',
},
}),
},
// Force file search tool:
toolChoice: { type: 'tool', toolName: 'file_search' },
});
```

<Note>
The tool must be named `file_search` when using Azure OpenAI's file search
functionality. This name is required by Azure OpenAI's API specification and
cannot be customized.
</Note>

#### Code Interpreter

The Azure OpenAI responses API supports the code interpreter tool through the `azure.tools.codeInterpreter` tool. This allows models to write and execute Python code.

```ts
import { azure } from '@ai-sdk/azure';
import { generateText } from 'ai';

const result = await generateText({
model: azure.responses('gpt-5'),
prompt: 'Write and run Python code to calculate the factorial of 10',
tools: {
code_interpreter: azure.tools.codeInterpreter({
// optional configuration:
container: {
fileIds: ['assistant-123', 'assistant-456'], // optional file IDs to make available
},
}),
},
});
```

The code interpreter tool can be configured with:

- **container**: Either a container ID string or an object with `fileIds` to specify uploaded files that should be available to the code interpreter

<Note>
The tool must be named `code_interpreter` when using Azure OpenAI's code
interpreter functionality. This name is required by Azure OpenAI's API
specification and cannot be customized.
</Note>

#### PDF support

The Azure OpenAI Responses API supports reading PDF files.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { azure } from '@ai-sdk/azure';
import { generateText } from 'ai';
import 'dotenv/config';

/**
* prepare
* Please add parameters in your .env file for initialize Azure OpenAI..
* AZURE_RESOURCE_NAME="<your_resource_name>"
* AZURE_API_KEY="<your_api_key>"
*/

async function main() {
// Basic text generation
const basicResult = await generateText({
model: azure.responses('gpt-5-mini'),
prompt:
'Create a program that generates five random numbers between 1 and 100 with two decimal places, and show me the execution results.',
tools: {
code_interpreter: azure.tools.codeInterpreter({}),
},
});

console.log('\n=== Basic Text Generation ===');
console.log(basicResult.text);
console.log('\n=== Other Outputs ===');
console.log(basicResult.toolCalls);
console.log(basicResult.toolResults);
}

main().catch(console.error);
44 changes: 44 additions & 0 deletions examples/ai-core/src/generate-text/azure-responses-file-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { azure } from '@ai-sdk/azure';
import { generateText } from 'ai';
import 'dotenv/config';

/**
* prepare 1
* Please add parameters in your .env file for initialize Azure OpenAI.
* AZURE_RESOURCE_NAME="<your_resource_name>"
* AZURE_API_KEY="<your_api_key>"
*
* prepare 2
* Please create vector store and put file in your vector.
* URL:AOAI vector store portal
* https://oai.azure.com/resource/vectorstore
*/

const VectorStoreId = 'vs_xxxxxxxxxxxxxxxxxxxxxxxx'; // put your vector store id.

async function main() {
// Basic text generation
const basicResult = await generateText({
model: azure.responses('gpt-4.1-mini'),
prompt: 'What is quantum computing?', // please question about your documents.
tools: {
file_search: azure.tools.fileSearch({
// optional configuration:
vectorStoreIds: [VectorStoreId],
maxNumResults: 10,
ranking: {
ranker: 'auto',
},
}),
},
// Force file search tool:
toolChoice: { type: 'tool', toolName: 'file_search' },
});

console.log('\n=== Basic Text Generation ===');
console.log(basicResult.text);
console.log(basicResult.toolCalls);
console.log(basicResult.toolResults);
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import 'dotenv/config';

async function main() {
// Basic text generation
const basicResult = await generateText({
model: openai.responses('gpt-4.1-mini'),
prompt:
'Create a program that generates five random numbers between 1 and 100 with two decimal places, and show me the execution results.',
tools: {
code_interpreter: openai.tools.codeInterpreter({}),
},
});

console.log('\n=== Basic Text Generation ===');
console.log(basicResult.text);
console.log('\n=== Other Outputs ===');
console.log(basicResult.toolCalls);
console.log(basicResult.toolResults);
}

main().catch(console.error);
39 changes: 39 additions & 0 deletions examples/ai-core/src/generate-text/openai-responses-file-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
import 'dotenv/config';

/**
* prepare
* Please create vector store and put file in your vector.
* URL:openai vector store dashboard
* https://platform.openai.com/storage/vector_stores/
*/

const VectorStoreId = 'vs_xxxxxxxxxxxxxxxxxxxxxxxx'; // put your vector store id.

async function main() {
// Basic text generation
const basicResult = await generateText({
model: openai.responses('gpt-4.1-mini'),
prompt: 'What is quantum computing?', // please question about your documents.
tools: {
file_search: openai.tools.fileSearch({
// optional configuration:
vectorStoreIds: [VectorStoreId],
maxNumResults: 10,
ranking: {
ranker: 'auto',
},
}),
},
// Force file search tool:
toolChoice: { type: 'tool', toolName: 'file_search' },
});

console.log('\n=== Basic Text Generation ===');
console.log(basicResult.text);
console.dir(basicResult.toolCalls, { depth: null });
console.dir(basicResult.toolResults, { depth: null });
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { azure } from '@ai-sdk/azure';
import { streamText } from 'ai';
import 'dotenv/config';

/**
* prepare
* Please add parameters in your .env file for initialize Azure OpenAI..
* AZURE_RESOURCE_NAME="<your_resource_name>"
* AZURE_API_KEY="<your_api_key>"
*/

async function main() {
// Basic text generation
const result = streamText({
model: azure.responses('gpt-5-mini'),
prompt:
'Create a program that generates five random numbers between 1 and 100 with two decimal places, and show me the execution results.',
tools: {
code_interpreter: azure.tools.codeInterpreter({}),
},
});

console.log('\n=== Basic Text Generation ===');
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
console.log('\n=== Other Outputs ===');
console.log(await result.toolCalls);
console.log(await result.toolResults);
}

main().catch(console.error);
48 changes: 48 additions & 0 deletions examples/ai-core/src/stream-text/azure-responses-file-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { azure } from '@ai-sdk/azure';
import { streamText } from 'ai';
import 'dotenv/config';

/**
* prepare 1
* Please add parameters in your .env file for initialize Azure OpenAI.
* AZURE_RESOURCE_NAME="<your_resource_name>"
* AZURE_API_KEY="<your_api_key>"
*
* prepare 2
* Please create vector store and put file in your vector.
* URL:AOAI vector store portal
* https://oai.azure.com/resource/vectorstore
*/

const VectorStoreId = 'vs_xxxxxxxxxxxxxxxxxxxxxxxx'; // put your vector store id.

async function main() {
// Basic text generation
const result = await streamText({
model: azure.responses('gpt-4.1-mini'),
prompt: 'What is quantum computing?', // please question about your documents.
tools: {
file_search: azure.tools.fileSearch({
// optional configuration:
vectorStoreIds: [VectorStoreId],
maxNumResults: 10,
ranking: {
ranker: 'auto',
},
}),
},
// Force file search tool:
toolChoice: { type: 'tool', toolName: 'file_search' },
});

console.log('\n=== Basic Text Generation ===');
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
console.log('\n=== Other Outputs ===');
console.dir(await result.toolCalls, { depth: Infinity });
console.dir(await result.toolResults, { depth: Infinity });
console.dir(await result.sources, { depth: Infinity });
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import 'dotenv/config';

async function main() {
// Basic text generation
const result = streamText({
model: openai.responses('gpt-4.1-mini'),
prompt:
'Create a program that generates five random numbers between 1 and 100 with two decimal places, and show me the execution results.',
tools: {
code_interpreter: openai.tools.codeInterpreter({}),
},
});

console.log('\n=== Basic Text Generation ===');
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
console.log('\n=== Other Outputs ===');
console.log(await result.toolCalls);
console.log(await result.toolResults);
}

main().catch(console.error);
42 changes: 42 additions & 0 deletions examples/ai-core/src/stream-text/openai-responses-file-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';
import 'dotenv/config';

/**
* prepare
* Please create vector store and put file in your vector.
* URL:openai vector store dashboard
* https://platform.openai.com/storage/vector_stores/
*/

const VectorStoreId = 'vs_xxxxxxxxxxxxxxxxxxxxxxxx'; // put your vector store id.

async function main() {
// Basic text generation
const result = await streamText({
model: openai.responses('gpt-4.1-mini'),
prompt: 'What is quantum computing?', // please question about your documents.
tools: {
file_search: openai.tools.fileSearch({
// optional configuration:
vectorStoreIds: [VectorStoreId],
maxNumResults: 10,
ranking: {
ranker: 'auto',
},
}),
},
// Force file search tool:
toolChoice: { type: 'tool', toolName: 'file_search' },
});

console.log('\n=== Basic Text Generation ===');
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
console.log('\n=== Other Outputs ===');
console.dir(await result.toolCalls, { depth: null });
console.dir(await result.toolResults, { depth: null });
}

main().catch(console.error);
Loading
Loading