Configure and use the Azure OpenAI provider with Vercel's AI SDK for language model integration in TypeScript/JavaScript projects
Configure the Azure OpenAI provider for Vercel's AI SDK to integrate Azure-hosted language models into your TypeScript/JavaScript applications.
This skill helps you install and configure the `@ai-sdk/azure` package, which provides language model support for Azure OpenAI API through Vercel's AI SDK framework. It enables seamless integration of Azure-hosted models like GPT-4 into your applications.
1. **Install the Azure provider package**
```bash
npm i @ai-sdk/azure
```
2. **Install the core AI SDK** (if not already installed)
```bash
npm i ai
```
3. **Add the AI SDK skill to your repository** (optional but recommended for coding agents)
```bash
npx skills add vercel/ai
```
Import the Azure provider in your TypeScript/JavaScript files:
```typescript
import { azure } from '@ai-sdk/azure';
import { generateText } from 'ai';
```
Set up Azure OpenAI credentials (typically in `.env` file):
```
AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_ENDPOINT=your-endpoint
```
```typescript
import { azure } from '@ai-sdk/azure';
import { generateText } from 'ai';
const { text } = await generateText({
model: azure('gpt-4o'), // Replace with your Azure deployment name
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
console.log(text);
```
**Text Generation:**
```typescript
const result = await generateText({
model: azure('your-deployment-name'),
prompt: 'Your prompt here',
});
```
**Streaming:**
```typescript
import { streamText } from 'ai';
const stream = await streamText({
model: azure('your-deployment-name'),
prompt: 'Your prompt here',
});
```
**Object Generation:**
```typescript
import { generateObject } from 'ai';
import { z } from 'zod';
const result = await generateObject({
model: azure('your-deployment-name'),
schema: z.object({ recipe: z.string() }),
prompt: 'Generate a recipe',
});
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/azure-openai-sdk-setup/raw