AI-103: Build Generative Apps with Foundry — Models, RAG, Tools and Evaluation
Building a generative application with Microsoft Foundry means writing the code that connects an app to a Foundry project, calls deployed models through the Foundry SDKs and the OpenAI-compatible v1 API, grounds answers in your own data with retrieval-augmented generation (RAG), chains model calls and function tools into multistep workflows, and evaluates the result for fabrication, relevance, quality and safety. This lesson covers each of those skills at the level of the actual calls: which endpoint and credential to use, what goes in the model parameter, how images, tool results and structured outputs are passed, how retrieval and query rewriting fit into the request flow, and which built-in evaluator measures which problem.
What you’ll learn
- Connect an app to a Foundry project with AIProjectClient and Entra ID, read project connections and deployments at run time, or call model deployments with the OpenAI() client on the keyless v1 endpoint.
- Call LLMs, small, code and multimodal models by deployment name, on the API surface each model supports, including image and PDF input.
- Manage multi-turn state, streaming and background mode with the Responses API.
- Implement RAG in application code: retrieve, ground with cited source IDs, rewrite follow-up queries and choose a supported implementation path now that On Your Data is retired.
- Build tool-augmented flows with function calling and control tool use with tool_choice and parallel_tool_calls.
- Design multistep pipelines with prompt chaining, strict structured outputs and Agent Framework graph workflows.
- Choose built-in quality and safety evaluators and configure a cloud evaluation run for datasets or generated responses.
The 10 parts · about 18 min of reading
- How does an application connect to a Foundry project?Start hereAIProjectClient takes the project endpoint and Entra ID only; the plain OpenAI() client uses the /openai/v1/ endpoint with a key or token.3 min
- How do you deploy and call LLMs, small models, code models and multimodal models?model= carries your deployment name, and each model's catalog card says which APIs and features, such as tool calling, it supports.2 min
- How do you send images and documents to a multimodal model?Images go in input_image and PDFs in input_file items, by URL, data URI or file_id; the detail setting trades tokens for resolution.1 min
- How do you manage multi-turn state, streaming and long-running calls?Turns link through previous_response_id or resent output items; streaming cuts perceived wait, and background mode outlives HTTP timeouts.1 min
- How do you implement RAG in an application?Classic RAG retrieves, augments then generates; On Your Data is retired, and grounded prompts cite chunk IDs the app maps to real URLs.2 min
- How do you write the retrieval step and handle follow-up questions?VectorizableTextQuery needs an index vectorizer; VectorizedQuery needs the index's embedding model. Rewrite follow-ups before you search.2 min
- How do tool-augmented flows with function calling work?The app runs each function_call and returns a function_call_output per call_id; tool_choice and parallel_tool_calls steer what gets called.2 min
- How do you design multistep reasoning pipelines and structured hand-offs?Chain focused prompts, hand off via strict structured outputs, and use Agent Framework graphs for branching, approvals and restarts.2 min
- Which evaluators detect fabrications, relevance, quality and safety?Groundedness flags added claims, Response Completeness missed points; quality evaluators need a judge deployment, safety evaluators don't.2 min
- How do you run a cloud evaluation in Foundry?evals.create declares data and criteria; a run scores a jsonl dataset or generates replies from a model or agent target.1 min
Mind map
How the exam tests this
Expect short scenarios — a developer, a Foundry project and a requirement such as keyless authentication, fewest code changes, no per-environment configuration, no stored responses, citations that must be real, or no judge-model deployment — followed by "what should you do or configure?". Many items show a few lines of Python using AIProjectClient, the OpenAI client, the Responses API or Azure AI Search and ask which value, field or call completes it, so know the exact names: endpoint formats, input_image and input_file items, call_id, response.output_text.delta, text.format versus response_format, VectorizedQuery versus VectorizableTextQuery, and {{item.*}} versus {{sample.output_text}}. Evaluation items hinge on matching the evaluator to what must be detected and to the data available, and several items ask you to select two actions that work together.
Key takeaways
- AIProjectClient takes the project endpoint https://<resource>.services.ai.azure.com/api/projects/<project> and an Entra ID token credential only; get_openai_client() gives an OpenAI client with the same sign-in. Read project connections with connections.get_default or connections.get (include_credentials=True only when you need a stored key).
- On the v1 API, use OpenAI() with a base_url ending in /openai/v1/, no api-version, and a bearer token provider for keyless calls; 404 points at the path, 401 at the credential.
- The model parameter is always the deployment name; discover names with project.deployments.list instead of hard-coding them per environment.
- Check the model card: codex models are Responses API only, partner models such as DeepSeek work through v1 chat completions, and some models have no tool calling.
- Images go in input_image (URL, base64 data URI or file_id) and PDFs in input_file (file_url or file_id); detail low saves tokens on coarse checks.
- Chain turns with previous_response_id, or with store=False resend the output items plus reasoning.encrypted_content; stream=True fixes perceived latency, background=True with store=True handles long tasks.
- RAG is retrieve, augment, generate: label chunks with IDs, let the app map IDs to URLs, allow a not-found answer, and rewrite follow-ups into standalone queries before searching.
- Query vectors must come from the same embedding model as the index, and a vector query always returns k results; On Your Data has been retired, so use Foundry IQ or app-side retrieval.
- Your code runs every function call and returns one function_call_output per call_id; tool_choice controls whether and which tool is called, parallel_tool_calls=False handles dependent calls.
- Groundedness catches added claims, Response Completeness catches missing points, safety evaluators need no judge deployment, and dataset runs map {{item.field}} while target runs use {{sample.output_text}}.
Part 1: How does an application connect to a Foundry project?
AIProjectClient takes the project endpoint and Entra ID only; the plain OpenAI() client uses the /openai/v1/ endpoint with a key or token.
Frequently asked questions
What endpoint and credential does AIProjectClient need?
AIProjectClient from azure-ai-projects takes the Foundry project endpoint, in the form https://<resource-name>.services.ai.azure.com/api/projects/<project-name>, and a Microsoft Entra ID token credential such as DefaultAzureCredential. Entra ID is the only authentication method the client supports, so passing an API key in AzureKeyCredential fails. DefaultAzureCredential uses a managed identity in Azure and your developer sign-in locally.
Why does a Foundry model call return DeploymentNotFound?
A DeploymentNotFound error usually means the model parameter holds the catalog model name, such as gpt-4.1-mini, instead of the name of a deployment on the resource. Foundry resolves the model value against deployment names, which you choose when you deploy. Pass the deployment name, or look it up at startup with project.deployments.list filtered by model name.
How does an app read a Foundry project connection at run time?
Use the connections operations on AIProjectClient. project.connections.get_default(ConnectionType.AZURE_AI_SEARCH) returns the project's default connection of that type, and project.connections.get("<name>") returns a named connection's endpoint and metadata. Secrets such as an API key are returned only when you pass include_credentials=True; if the app authenticates to the target service with Entra ID, it needs only the endpoint.
Sign up free to mark lessons complete, bookmark topics and track your exam readiness.