Build AI applications using Azure AI Projects SDK for JavaScript (@azure/ai-projects). Use when working with Foundry project clients, agents, connections, deployments, datasets, indexes, evaluations, or getting OpenAI clients.
Add this skill
npx mdskills install sickn33/azure-ai-projects-tsComprehensive Azure AI SDK reference with clear examples across agents, connections, and tools
1---2name: azure-ai-projects-ts3description: Build AI applications using Azure AI Projects SDK for JavaScript (@azure/ai-projects). Use when working with Foundry project clients, agents, connections, deployments, datasets, indexes, evaluations, or getting OpenAI clients.4package: "@azure/ai-projects"5---67# Azure AI Projects SDK for TypeScript89High-level SDK for Azure AI Foundry projects with agents, connections, deployments, and evaluations.1011## Installation1213```bash14npm install @azure/ai-projects @azure/identity15```1617For tracing:18```bash19npm install @azure/monitor-opentelemetry @opentelemetry/api20```2122## Environment Variables2324```bash25AZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>26MODEL_DEPLOYMENT_NAME=gpt-4o27```2829## Authentication3031```typescript32import { AIProjectClient } from "@azure/ai-projects";33import { DefaultAzureCredential } from "@azure/identity";3435const client = new AIProjectClient(36 process.env.AZURE_AI_PROJECT_ENDPOINT!,37 new DefaultAzureCredential()38);39```4041## Operation Groups4243| Group | Purpose |44|-------|---------|45| `client.agents` | Create and manage AI agents |46| `client.connections` | List connected Azure resources |47| `client.deployments` | List model deployments |48| `client.datasets` | Upload and manage datasets |49| `client.indexes` | Create and manage search indexes |50| `client.evaluators` | Manage evaluation metrics |51| `client.memoryStores` | Manage agent memory |5253## Getting OpenAI Client5455```typescript56const openAIClient = await client.getOpenAIClient();5758// Use for responses59const response = await openAIClient.responses.create({60 model: "gpt-4o",61 input: "What is the capital of France?"62});6364// Use for conversations65const conversation = await openAIClient.conversations.create({66 items: [{ type: "message", role: "user", content: "Hello!" }]67});68```6970## Agents7172### Create Agent7374```typescript75const agent = await client.agents.createVersion("my-agent", {76 kind: "prompt",77 model: "gpt-4o",78 instructions: "You are a helpful assistant."79});80```8182### Agent with Tools8384```typescript85// Code Interpreter86const agent = await client.agents.createVersion("code-agent", {87 kind: "prompt",88 model: "gpt-4o",89 instructions: "You can execute code.",90 tools: [{ type: "code_interpreter", container: { type: "auto" } }]91});9293// File Search94const agent = await client.agents.createVersion("search-agent", {95 kind: "prompt",96 model: "gpt-4o",97 tools: [{ type: "file_search", vector_store_ids: [vectorStoreId] }]98});99100// Web Search101const agent = await client.agents.createVersion("web-agent", {102 kind: "prompt",103 model: "gpt-4o",104 tools: [{105 type: "web_search_preview",106 user_location: { type: "approximate", country: "US", city: "Seattle" }107 }]108});109110// Azure AI Search111const agent = await client.agents.createVersion("aisearch-agent", {112 kind: "prompt",113 model: "gpt-4o",114 tools: [{115 type: "azure_ai_search",116 azure_ai_search: {117 indexes: [{118 project_connection_id: connectionId,119 index_name: "my-index",120 query_type: "simple"121 }]122 }123 }]124});125126// Function Tool127const agent = await client.agents.createVersion("func-agent", {128 kind: "prompt",129 model: "gpt-4o",130 tools: [{131 type: "function",132 function: {133 name: "get_weather",134 description: "Get weather for a location",135 strict: true,136 parameters: {137 type: "object",138 properties: { location: { type: "string" } },139 required: ["location"]140 }141 }142 }]143});144145// MCP Tool146const agent = await client.agents.createVersion("mcp-agent", {147 kind: "prompt",148 model: "gpt-4o",149 tools: [{150 type: "mcp",151 server_label: "my-mcp",152 server_url: "https://mcp-server.example.com",153 require_approval: "always"154 }]155});156```157158### Run Agent159160```typescript161const openAIClient = await client.getOpenAIClient();162163// Create conversation164const conversation = await openAIClient.conversations.create({165 items: [{ type: "message", role: "user", content: "Hello!" }]166});167168// Generate response using agent169const response = await openAIClient.responses.create(170 { conversation: conversation.id },171 { body: { agent: { name: agent.name, type: "agent_reference" } } }172);173174// Cleanup175await openAIClient.conversations.delete(conversation.id);176await client.agents.deleteVersion(agent.name, agent.version);177```178179## Connections180181```typescript182// List all connections183for await (const conn of client.connections.list()) {184 console.log(conn.name, conn.type);185}186187// Get connection by name188const conn = await client.connections.get("my-connection");189190// Get connection with credentials191const connWithCreds = await client.connections.getWithCredentials("my-connection");192193// Get default connection by type194const defaultAzureOpenAI = await client.connections.getDefault("AzureOpenAI", true);195```196197## Deployments198199```typescript200// List all deployments201for await (const deployment of client.deployments.list()) {202 if (deployment.type === "ModelDeployment") {203 console.log(deployment.name, deployment.modelName);204 }205}206207// Filter by publisher208for await (const d of client.deployments.list({ modelPublisher: "OpenAI" })) {209 console.log(d.name);210}211212// Get specific deployment213const deployment = await client.deployments.get("gpt-4o");214```215216## Datasets217218```typescript219// Upload single file220const dataset = await client.datasets.uploadFile(221 "my-dataset",222 "1.0",223 "./data/training.jsonl"224);225226// Upload folder227const dataset = await client.datasets.uploadFolder(228 "my-dataset",229 "2.0",230 "./data/documents/"231);232233// Get dataset234const ds = await client.datasets.get("my-dataset", "1.0");235236// List versions237for await (const version of client.datasets.listVersions("my-dataset")) {238 console.log(version);239}240241// Delete242await client.datasets.delete("my-dataset", "1.0");243```244245## Indexes246247```typescript248import { AzureAISearchIndex } from "@azure/ai-projects";249250const indexConfig: AzureAISearchIndex = {251 name: "my-index",252 type: "AzureSearch",253 version: "1",254 indexName: "my-index",255 connectionName: "search-connection"256};257258// Create index259const index = await client.indexes.createOrUpdate("my-index", "1", indexConfig);260261// List indexes262for await (const idx of client.indexes.list()) {263 console.log(idx.name);264}265266// Delete267await client.indexes.delete("my-index", "1");268```269270## Key Types271272```typescript273import {274 AIProjectClient,275 AIProjectClientOptionalParams,276 Connection,277 ModelDeployment,278 DatasetVersionUnion,279 AzureAISearchIndex280} from "@azure/ai-projects";281```282283## Best Practices2842851. **Use getOpenAIClient()** - For responses, conversations, files, and vector stores2862. **Version your agents** - Use `createVersion` for reproducible agent definitions2873. **Clean up resources** - Delete agents, conversations when done2884. **Use connections** - Get credentials from project connections, don't hardcode2895. **Filter deployments** - Use `modelPublisher` filter to find specific models290
Full transparency — inspect the skill content before installing.