diff --git a/samples/csharp/quickstart/chat-with-agent/quickstart-chat-with-agent.cs b/samples/csharp/quickstart/chat-with-agent/quickstart-chat-with-agent.cs index 05f92b67a..1f6113abf 100644 --- a/samples/csharp/quickstart/chat-with-agent/quickstart-chat-with-agent.cs +++ b/samples/csharp/quickstart/chat-with-agent/quickstart-chat-with-agent.cs @@ -1,30 +1,29 @@ +using Azure.Identity; using Azure.AI.Projects; using Azure.AI.Projects.OpenAI; -using Azure.Identity; using OpenAI.Responses; #pragma warning disable OPENAI001 -string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT") - ?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'"); -string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") - ?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'"); -string agentName = Environment.GetEnvironmentVariable("AGENT_NAME") - ?? throw new InvalidOperationException("Missing environment variable 'AGENT_NAME'"); +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +var projectEndpoint = "your_project_endpoint"; +var agentName = "your_agent_name"; -AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential()); +// Create project client to call Foundry API +AIProjectClient projectClient = new( + endpoint: new Uri(projectEndpoint), + tokenProvider: new DefaultAzureCredential()); -// Optional Step: Create a conversation to use with the agent +// Create a conversation for multi-turn chat ProjectConversation conversation = projectClient.OpenAI.Conversations.CreateProjectConversation(); +// Chat with the agent to answer questions ProjectResponsesClient responsesClient = projectClient.OpenAI.GetProjectResponsesClientForAgent( defaultAgent: agentName, defaultConversationId: conversation.Id); - -// Chat with the agent to answer questions ResponseResult response = responsesClient.CreateResponse("What is the size of France in square miles?"); Console.WriteLine(response.GetOutputText()); -// Optional Step: Ask a follow-up question in the same conversation +// Ask a follow-up question in the same conversation response = responsesClient.CreateResponse("And what is the capital city?"); Console.WriteLine(response.GetOutputText()); \ No newline at end of file diff --git a/samples/csharp/quickstart/create-agent/quickstart-create-agent.cs b/samples/csharp/quickstart/create-agent/quickstart-create-agent.cs index dab5d95e2..c4e70e2bd 100644 --- a/samples/csharp/quickstart/create-agent/quickstart-create-agent.cs +++ b/samples/csharp/quickstart/create-agent/quickstart-create-agent.cs @@ -1,27 +1,23 @@ +using Azure.Identity; using Azure.AI.Projects; using Azure.AI.Projects.OpenAI; -using Azure.Identity; -string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT") -?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'"); -string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") -?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'"); -string agentName = Environment.GetEnvironmentVariable("AGENT_NAME") -?? throw new InvalidOperationException("Missing environment variable 'AGENT_NAME'"); +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +var projectEndpoint = "your_project_endpoint"; +var agentName = "your_agent_name"; -AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential()); +// Create project client to call Foundry API +AIProjectClient projectClient = new( + endpoint: new Uri(projectEndpoint), + tokenProvider: new DefaultAzureCredential()); -AgentDefinition agentDefinition = new PromptAgentDefinition(modelDeploymentName) +// Create an agent with a model and instructions +AgentDefinition agentDefinition = new PromptAgentDefinition("gpt-5-mini") { Instructions = "You are a helpful assistant that answers general questions", }; -AgentVersion newAgentVersion = projectClient.Agents.CreateAgentVersion( +AgentVersion agent = projectClient.Agents.CreateAgentVersion( agentName, options: new(agentDefinition)); - -List agentVersions = [..projectClient.Agents.GetAgentVersions(agentName)]; -foreach (AgentVersion agentVersion in agentVersions) -{ - Console.WriteLine($"Agent: {agentVersion.Id}, Name: {agentVersion.Name}, Version: {agentVersion.Version}"); -} +Console.WriteLine($"Agent created (id: {agent.Id}, name: {agent.Name}, version: {agent.Version})"); diff --git a/samples/csharp/quickstart/responses/quickstart-responses.cs b/samples/csharp/quickstart/responses/quickstart-responses.cs index d980fa97d..c8816a37b 100644 --- a/samples/csharp/quickstart/responses/quickstart-responses.cs +++ b/samples/csharp/quickstart/responses/quickstart-responses.cs @@ -1,18 +1,20 @@ +using Azure.Identity; using Azure.AI.Projects; using Azure.AI.Projects.OpenAI; -using Azure.Identity; using OpenAI.Responses; #pragma warning disable OPENAI001 -string projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT") -?? throw new InvalidOperationException("Missing environment variable 'PROJECT_ENDPOINT'"); -string modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME") -?? throw new InvalidOperationException("Missing environment variable 'MODEL_DEPLOYMENT_NAME'"); - -AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential()); +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +var projectEndpoint = "your_project_endpoint"; -ProjectResponsesClient responseClient = projectClient.OpenAI.GetProjectResponsesClientForModel(modelDeploymentName); -ResponseResult response = await responseClient.CreateResponseAsync("What is the size of France in square miles?"); +// Create project client to call Foundry API +AIProjectClient projectClient = new( + endpoint: new Uri(projectEndpoint), + tokenProvider: new DefaultAzureCredential()); +// Run a responses API call +ProjectResponsesClient responseClient = projectClient.OpenAI.GetProjectResponsesClientForModel("gpt-5-mini"); +ResponseResult response = await responseClient.CreateResponseAsync( + "What is the size of France in square miles?"); Console.WriteLine(response.GetOutputText()); diff --git a/samples/java/quickstart/chat-with-agent/src/main/java/com/azure/ai/agents/ChatWithAgent.java b/samples/java/quickstart/chat-with-agent/src/main/java/com/azure/ai/agents/ChatWithAgent.java index 05bd0340e..73ff32bd9 100644 --- a/samples/java/quickstart/chat-with-agent/src/main/java/com/azure/ai/agents/ChatWithAgent.java +++ b/samples/java/quickstart/chat-with-agent/src/main/java/com/azure/ai/agents/ChatWithAgent.java @@ -1,64 +1,33 @@ package com.azure.ai.agents; -import com.azure.ai.agents.models.AgentReference; -import com.azure.ai.agents.models.AgentVersionDetails; -import com.azure.ai.agents.models.PromptAgentDefinition; -import com.azure.identity.AuthenticationUtil; import com.azure.identity.DefaultAzureCredentialBuilder; -import com.openai.azure.AzureOpenAIServiceVersion; -import com.openai.azure.AzureUrlPathMode; -import com.openai.client.OpenAIClient; -import com.openai.client.okhttp.OpenAIOkHttpClient; -import com.openai.credential.BearerTokenCredential; import com.openai.models.conversations.Conversation; -import com.openai.models.conversations.items.ItemCreateParams; -import com.openai.models.responses.EasyInputMessage; import com.openai.models.responses.Response; import com.openai.models.responses.ResponseCreateParams; public class ChatWithAgent { public static void main(String[] args) { - String endpoint = Configuration.getGlobalConfiguration().get("AZURE_AGENTS_ENDPOINT"); - String agentName = "MyAgent"; - - AgentsClient agentsClient = new AgentsClientBuilder() - .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint(endpoint) - .buildAgentsClient(); + // Format: "https://resource_name.ai.azure.com/api/projects/project_name" + String projectEndpoint = "your_project_endpoint"; + String agentName = "your_agent_name"; - AgentDetails agent = agentsClient.getAgent(agentName); + // Create clients to call Foundry API + AgentsClientBuilder builder = new AgentsClientBuilder() + .credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(projectEndpoint); + ResponsesClient responsesClient = builder.buildResponsesClient(); + ConversationsClient conversationsClient = builder.buildConversationsClient(); + // Create a conversation for multi-turn chat Conversation conversation = conversationsClient.getConversationService().create(); - conversationsClient.getConversationService().items().create( - ItemCreateParams.builder() - .conversationId(conversation.id()) - .addItem(EasyInputMessage.builder() - .role(EasyInputMessage.Role.SYSTEM) - .content("You are a helpful assistant that speaks like a pirate.") - .build() - ).addItem(EasyInputMessage.builder() - .role(EasyInputMessage.Role.USER) - .content("Hello, agent!") - .build() - ).build() - ); - - AgentReference agentReference = new AgentReference(agent.getName()).setVersion(agent.getVersion()); - Response response = responsesClient.createWithAgentConversation(agentReference, conversation.id()); - - OpenAIClient client = OpenAIOkHttpClient.builder() - .baseUrl(endpoint.endsWith("/") ? endpoint + "openai" : endpoint + "/openai") - .azureUrlPathMode(AzureUrlPathMode.UNIFIED) - .credential(BearerTokenCredential.create(AuthenticationUtil.getBearerTokenSupplier( - new DefaultAzureCredentialBuilder().build(), "https://ai.azure.com/.default"))) - .azureServiceVersion(AzureOpenAIServiceVersion.fromString("2025-11-15-preview")) - .build(); + // TODO: Java SDK does not yet support passing conversation ID or agent reference + // to ResponseCreateParams. Update once the SDK adds agent+conversation support. + // Chat with the agent to answer questions ResponseCreateParams responseRequest = new ResponseCreateParams.Builder() - .input("Hello, how can you help me?") - .model(model) - .build(); - - Response result = client.responses().create(responseRequest); + .input("What is the size of France in square miles?") + .build(); + Response response = responsesClient.getResponseService().create(responseRequest); + System.out.println(response.output()); } } \ No newline at end of file diff --git a/samples/java/quickstart/create-agent/src/main/java/com/azure/ai/agents/CreateAgent.java b/samples/java/quickstart/create-agent/src/main/java/com/azure/ai/agents/CreateAgent.java index 6b81d2341..da3997c95 100644 --- a/samples/java/quickstart/create-agent/src/main/java/com/azure/ai/agents/CreateAgent.java +++ b/samples/java/quickstart/create-agent/src/main/java/com/azure/ai/agents/CreateAgent.java @@ -2,21 +2,23 @@ import com.azure.ai.agents.models.AgentVersionDetails; import com.azure.ai.agents.models.PromptAgentDefinition; -import com.azure.core.util.Configuration; import com.azure.identity.DefaultAzureCredentialBuilder; public class CreateAgent { public static void main(String[] args) { - String endpoint = Configuration.getGlobalConfiguration().get("PROJECT_ENDPOINT"); - String model = Configuration.getGlobalConfiguration().get("MODEL_DEPLOYMENT_NAME"); - // Code sample for creating an agent + // Format: "https://resource_name.ai.azure.com/api/projects/project_name" + String projectEndpoint = "your_project_endpoint"; + String agentName = "your_agent_name"; + + // Create agents client to call Foundry API AgentsClient agentsClient = new AgentsClientBuilder() .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint(endpoint) + .endpoint(projectEndpoint) .buildAgentsClient(); - PromptAgentDefinition request = new PromptAgentDefinition(model); - AgentVersionDetails agent = agentsClient.createAgentVersion("MyAgent", request); + // Create an agent with a model and instructions + PromptAgentDefinition request = new PromptAgentDefinition("gpt-5-mini"); + AgentVersionDetails agent = agentsClient.createAgentVersion(agentName, request); System.out.println("Agent ID: " + agent.getId()); System.out.println("Agent Name: " + agent.getName()); diff --git a/samples/java/quickstart/responses/src/main/java/com/azure/ai/agents/CreateResponse.java b/samples/java/quickstart/responses/src/main/java/com/azure/ai/agents/CreateResponse.java index 12188eb50..b96906413 100644 --- a/samples/java/quickstart/responses/src/main/java/com/azure/ai/agents/CreateResponse.java +++ b/samples/java/quickstart/responses/src/main/java/com/azure/ai/agents/CreateResponse.java @@ -1,31 +1,26 @@ package com.azure.ai.agents; -import com.azure.core.util.Configuration; import com.azure.identity.DefaultAzureCredentialBuilder; import com.openai.models.responses.Response; import com.openai.models.responses.ResponseCreateParams; public class CreateResponse { public static void main(String[] args) { - String endpoint = Configuration.getGlobalConfiguration().get("PROJECT_ENDPOINT"); - String model = Configuration.getGlobalConfiguration().get("MODEL_DEPLOYMENT_NAME"); - // Code sample for creating a response + // Format: "https://resource_name.ai.azure.com/api/projects/project_name" + String projectEndpoint = "your_project_endpoint"; + + // Create responses client to call Foundry API ResponsesClient responsesClient = new AgentsClientBuilder() .credential(new DefaultAzureCredentialBuilder().build()) - .endpoint(endpoint) - .serviceVersion(AgentsServiceVersion.V2025_11_15_PREVIEW) + .endpoint(projectEndpoint) .buildResponsesClient(); + // Run a responses API call ResponseCreateParams responseRequest = new ResponseCreateParams.Builder() - .input("Hello, how can you help me?") - .model(model) + .input("What is the size of France in square miles?") + .model("gpt-5-mini") // supports all Foundry direct models .build(); - Response response = responsesClient.getResponseService().create(responseRequest); - - System.out.println("Response ID: " + response.id()); - System.out.println("Response Model: " + response.model()); - System.out.println("Response Created At: " + response.createdAt()); - System.out.println("Response Output: " + response.output()); + System.out.println(response.output()); } } \ No newline at end of file diff --git a/samples/python/quickstart/quickstart-chat-with-agent.py b/samples/python/quickstart/quickstart-chat-with-agent.py index 4d70ac4af..e5239c532 100644 --- a/samples/python/quickstart/quickstart-chat-with-agent.py +++ b/samples/python/quickstart/quickstart-chat-with-agent.py @@ -1,34 +1,32 @@ -import os -from dotenv import load_dotenv from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient -load_dotenv() +# Format: "https://resource_name.ai.azure.com/api/projects/project_name" +FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint" +AGENT_NAME = "your_agent_name" -project_client = AIProjectClient( - endpoint=os.environ["PROJECT_ENDPOINT"], +# Create project and openai clients to call Foundry API +project = AIProjectClient( + endpoint=FOUNDRY_PROJECT_ENDPOINT, credential=DefaultAzureCredential(), ) +openai = project.get_openai_client() -agent_name = os.environ["AGENT_NAME"] -openai_client = project_client.get_openai_client() - -# Optional Step: Create a conversation to use with the agent -conversation = openai_client.conversations.create() -print(f"Created conversation (id: {conversation.id})") +# Create a conversation for multi-turn chat +conversation = openai.conversations.create() # Chat with the agent to answer questions -response = openai_client.responses.create( - conversation=conversation.id, #Optional conversation context for multi-turn - extra_body={"agent": {"name": agent_name, "type": "agent_reference"}}, +response = openai.responses.create( + conversation=conversation.id, + extra_body={"agent": {"name": AGENT_NAME, "type": "agent_reference"}}, input="What is the size of France in square miles?", ) -print(f"Response output: {response.output_text}") +print(response.output_text) -# Optional Step: Ask a follow-up question in the same conversation -response = openai_client.responses.create( +# Ask a follow-up question in the same conversation +response = openai.responses.create( conversation=conversation.id, - extra_body={"agent": {"name": agent_name, "type": "agent_reference"}}, + extra_body={"agent": {"name": AGENT_NAME, "type": "agent_reference"}}, input="And what is the capital city?", ) -print(f"Response output: {response.output_text}") +print(response.output_text) diff --git a/samples/python/quickstart/quickstart-create-agent.py b/samples/python/quickstart/quickstart-create-agent.py index bf3eca8ac..a1ea18fb2 100644 --- a/samples/python/quickstart/quickstart-create-agent.py +++ b/samples/python/quickstart/quickstart-create-agent.py @@ -1,20 +1,22 @@ -import os -from dotenv import load_dotenv from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import PromptAgentDefinition -load_dotenv() +# Format: "https://resource_name.ai.azure.com/api/projects/project_name" +FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint" +AGENT_NAME = "your_agent_name" -project_client = AIProjectClient( - endpoint=os.environ["PROJECT_ENDPOINT"], +# Create project client to call Foundry API +project = AIProjectClient( + endpoint=FOUNDRY_PROJECT_ENDPOINT, credential=DefaultAzureCredential(), ) -agent = project_client.agents.create_version( - agent_name=os.environ["AGENT_NAME"], +# Create an agent with a model and instructions +agent = project.agents.create_version( + agent_name=AGENT_NAME, definition=PromptAgentDefinition( - model=os.environ["MODEL_DEPLOYMENT_NAME"], + model="gpt-5-mini", # supports all Foundry direct models instructions="You are a helpful assistant that answers general questions", ), ) diff --git a/samples/python/quickstart/quickstart-responses.py b/samples/python/quickstart/quickstart-responses.py index 75bdc0ada..396ff22b7 100644 --- a/samples/python/quickstart/quickstart-responses.py +++ b/samples/python/quickstart/quickstart-responses.py @@ -1,22 +1,19 @@ -import os -from dotenv import load_dotenv from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient -load_dotenv() +# Format: "https://resource_name.ai.azure.com/api/projects/project_name" +FOUNDRY_PROJECT_ENDPOINT = "your_project_endpoint" -print(f"Using PROJECT_ENDPOINT: {os.environ['PROJECT_ENDPOINT']}") -print(f"Using MODEL_DEPLOYMENT_NAME: {os.environ['MODEL_DEPLOYMENT_NAME']}") - -project_client = AIProjectClient( - endpoint=os.environ["PROJECT_ENDPOINT"], +# Create project and openai clients to call Foundry API +project = AIProjectClient( + endpoint=FOUNDRY_PROJECT_ENDPOINT, credential=DefaultAzureCredential(), ) +openai = project.get_openai_client() -openai_client = project_client.get_openai_client() - -response = openai_client.responses.create( - model=os.environ["MODEL_DEPLOYMENT_NAME"], +# Run a responses API call +response = openai.responses.create( + model="gpt-5-mini", # supports all Foundry direct models input="What is the size of France in square miles?", ) print(f"Response output: {response.output_text}") \ No newline at end of file diff --git a/samples/typescript/quickstart/chat-with-agent/src/quickstart-chat-with-agent.ts b/samples/typescript/quickstart/chat-with-agent/src/quickstart-chat-with-agent.ts index f6818fc3d..5f178bd52 100644 --- a/samples/typescript/quickstart/chat-with-agent/src/quickstart-chat-with-agent.ts +++ b/samples/typescript/quickstart/chat-with-agent/src/quickstart-chat-with-agent.ts @@ -1,52 +1,41 @@ import { DefaultAzureCredential } from "@azure/identity"; import { AIProjectClient } from "@azure/ai-projects"; -import "dotenv/config"; -const projectEndpoint = process.env["PROJECT_ENDPOINT"] || ""; -const deploymentName = process.env["MODEL_DEPLOYMENT_NAME"] || ""; +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +const PROJECT_ENDPOINT = "your_project_endpoint"; +const AGENT_NAME = "your_agent_name"; async function main(): Promise { - const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential()); - const openAIClient = project.getOpenAIClient(); - - // Create agent - console.log("Creating agent..."); - const agent = await project.agents.createVersion("my-agent-basic", { - kind: "prompt", - model: deploymentName, - instructions: "You are a helpful assistant that answers general questions", - }); - console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`); - - // Create conversation with initial user message - // You can save the conversation ID to database to retrieve later - console.log("\nCreating conversation with initial user message..."); - const conversation = await openAIClient.conversations.create({ - items: [ - { type: "message", role: "user", content: "What is the size of France in square miles?" }, - ], - }); - console.log(`Created conversation with initial user message (id: ${conversation.id})`); + // Create project and openai clients to call Foundry API + const project = new AIProjectClient(PROJECT_ENDPOINT, new DefaultAzureCredential()); + const openai = await project.getOpenAIClient(); - // Generate response using the agent - console.log("\nGenerating response..."); - const response = await openAIClient.responses.create( + // Create a conversation for multi-turn chat + const conversation = await openai.conversations.create(); + + // Chat with the agent to answer questions + const response = await openai.responses.create( { conversation: conversation.id, + input: "What is the size of France in square miles?", }, { - body: { agent: { name: agent.name, type: "agent_reference" } }, + body: { agent: { name: AGENT_NAME, type: "agent_reference" } }, }, ); - console.log(`Response output: ${response.output_text}`); - - // Clean up - console.log("\nCleaning up resources..."); - await openAIClient.conversations.delete(conversation.id); - console.log("Conversation deleted"); + console.log(response.output_text); - await project.agents.deleteVersion(agent.name, agent.version); - console.log("Agent deleted"); + // Ask a follow-up question in the same conversation + const response2 = await openai.responses.create( + { + conversation: conversation.id, + input: "And what is the capital city?", + }, + { + body: { agent: { name: AGENT_NAME, type: "agent_reference" } }, + }, + ); + console.log(response2.output_text); } main().catch(console.error); \ No newline at end of file diff --git a/samples/typescript/quickstart/create-agent/src/quickstart-create-agent.ts b/samples/typescript/quickstart/create-agent/src/quickstart-create-agent.ts index 120ce8f23..8df6e7095 100644 --- a/samples/typescript/quickstart/create-agent/src/quickstart-create-agent.ts +++ b/samples/typescript/quickstart/create-agent/src/quickstart-create-agent.ts @@ -1,18 +1,21 @@ import { DefaultAzureCredential } from "@azure/identity"; import { AIProjectClient } from "@azure/ai-projects"; -import "dotenv/config"; -const projectEndpoint = process.env["PROJECT_ENDPOINT"] || ""; -const deploymentName = process.env["MODEL_DEPLOYMENT_NAME"] || ""; +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +const PROJECT_ENDPOINT = "your_project_endpoint"; +const AGENT_NAME = "your_agent_name"; async function main(): Promise { - const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential()); - const agent = await project.agents.createVersion("my-agent-basic", { + // Create project client to call Foundry API + const project = new AIProjectClient(PROJECT_ENDPOINT, new DefaultAzureCredential()); + + // Create an agent with a model and instructions + const agent = await project.agents.createVersion(AGENT_NAME, { kind: "prompt", - model: deploymentName, + model: "gpt-5-mini", // supports all Foundry direct models instructions: "You are a helpful assistant that answers general questions", - }); - console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`); + }); + console.log(`Agent created (id: ${agent.id}, name: ${agent.name}, version: ${agent.version})`); } main().catch(console.error); \ No newline at end of file diff --git a/samples/typescript/quickstart/responses/src/quickstart-responses.ts b/samples/typescript/quickstart/responses/src/quickstart-responses.ts index ad68301a1..9120ae67e 100644 --- a/samples/typescript/quickstart/responses/src/quickstart-responses.ts +++ b/samples/typescript/quickstart/responses/src/quickstart-responses.ts @@ -1,15 +1,17 @@ import { DefaultAzureCredential } from "@azure/identity"; import { AIProjectClient } from "@azure/ai-projects"; -import "dotenv/config"; -const projectEndpoint = process.env["PROJECT_ENDPOINT"] || ""; -const deploymentName = process.env["MODEL_DEPLOYMENT_NAME"] || ""; +// Format: "https://resource_name.ai.azure.com/api/projects/project_name" +const PROJECT_ENDPOINT = "your_project_endpoint"; async function main(): Promise { - const project = new AIProjectClient(projectEndpoint, new DefaultAzureCredential()); - const openAIClient = project.getOpenAIClient(); - const response = await openAIClient.responses.create({ - model: deploymentName, + // Create project and openai clients to call Foundry API + const project = new AIProjectClient(PROJECT_ENDPOINT, new DefaultAzureCredential()); + const openai = await project.getOpenAIClient(); + + // Run a responses API call + const response = await openai.responses.create({ + model: "gpt-5-mini", // supports all Foundry direct models input: "What is the size of France in square miles?", }); console.log(`Response output: ${response.output_text}`);