Skip to main content

Fixed: "Service request failed. Status: 404 (Not Found)" Generating Embeddings from a Microsoft Foundry Project

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

My RAG app asked its Microsoft Foundry project's OpenAI client, the one it uses for its chat model, for an embedding client, and crashed at startup: System.ClientModel.ClientResultException: Service request failed. Status: 404 (Not Found). The project endpoint doesn't route embedding requests. An EmbeddingClient on the resource's /openai/v1/ endpoint, the way Microsoft's embeddings documentation shows, fixed it.

What I Was Doing​

I was building MuseumGuide, a console app that answers visitors' questions about a museum from its visitor guide, with retrieval-augmented generation (RAG). It has two kinds of model:

  • An embedding model, text-embedding-3-small, turns each of the guide's five pages into an embedding when the app starts: a list of numbers that stands for the text's meaning. Before every answer, the app embeds the question too, and picks the two pages whose embeddings are closest to it.
  • A chat model, gpt-5.6-luna, answers the question from those two pages.

The project references Microsoft.Agents.AI.Foundry 1.28.0-preview.261106.1, a preview package, with Azure.Identity 1.21.0 and System.Numerics.Tensors 10.0.15. The app connects to the Foundry project and gets its OpenAI client:

Program.cs (the first lines, as it was)
using System.Numerics.Tensors;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

var openAI = new AIProjectClient(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
new AzureCliCredential())
.GetProjectOpenAIClient();

The agent's chat model comes from that client, so I asked the same client for the embedding model:

Program.cs (the embeddings, as it was)
// An embedding model turns text into a list of numbers, a vector. Texts with similar meanings get similar vectors.
IEmbeddingGenerator<string, Embedding<float>> embeddings = openAI
.GetEmbeddingClient("text-embedding-3-small")
.AsIEmbeddingGenerator();

// Embed every page once, when the app starts.
GeneratedEmbeddings<Embedding<float>> pageVectors = await embeddings.GenerateAsync(guide.Select(page => page.Text));
Program.cs (the search and the agent)
// RAG: before every model call, search the guide with the question and add the best pages to the request.
TextSearchProvider guideSearch = new(SearchGuideAsync, new TextSearchProviderOptions
{
SearchTime = TextSearchProviderOptions.TextSearchBehavior.BeforeAIInvoke,
});

AIAgent museumGuide = openAI
.GetChatClient("gpt-5.6-luna")
.AsIChatClient()
.AsAIAgent(new ChatClientAgentOptions
{
Name = "MuseumGuide",
ChatOptions = new ChatOptions
{
Instructions = "You answer visitors' questions about the City Museum in one or two sentences. Answer only from the " +
"museum's guide that comes with the question, and name the page you used. If the guide doesn't answer the " +
"question, say that you don't know.",
},
AIContextProviders = [guideSearch],
});
  • GetEmbeddingClient("text-embedding-3-small") asks the project's OpenAI client for an embedding client for that deployment, and AsIEmbeddingGenerator() wraps it in the IEmbeddingGenerator interface the rest of the app uses.
  • GenerateAsync on line 33 embeds every page of the guide, once, when the app starts.
  • The TextSearchProvider runs the search before every model call and adds the pages it finds to the request.
  • The agent gets its chat model from the same openAI client, with GetChatClient("gpt-5.6-luna").

What I Expected​

The guide's pages embedded, then three answers. text-embedding-3-small is deployed on the same Foundry resource as the chat model, and the project's client serves the chat model's requests.

What I Got​

Terminal
dotnet run
Output
Unhandled exception. System.ClientModel.ClientResultException: Service request failed.
Status: 404 (Not Found)

at OpenAI.ClientPipelineExtensions.ProcessMessageAsync(ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync(BinaryContent content, RequestOptions options)
at OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync(IEnumerable`1 inputs, EmbeddingGenerationOptions options, RequestOptions requestOptions)
at Microsoft.Extensions.AI.OpenAIEmbeddingGenerator.GenerateAsync(IEnumerable`1 values, EmbeddingGenerationOptions options, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in /Users/you/source/MuseumGuide/Program.cs:line 33
at Program.<Main>(String[] args)

macOS-style terminal window titled Terminal — MuseumGuide showing dotnet run crashing with Unhandled exception. System.ClientModel.ClientResultException: Service request failed. Status: 404 (Not Found), thrown from OpenAI.Embeddings.EmbeddingClient.GenerateEmbeddingsAsync through Microsoft.Extensions.AI.OpenAIEmbeddingGenerator.GenerateAsync, called from line 33 of Program.cs

The app crashed before it asked a single question.

What I Checked​

Where it failed. The stack trace ends in my Program.cs at line 33, the GenerateAsync call that embeds the guide's pages, and the request itself was sent by EmbeddingClient.GenerateEmbeddingsAsync. Creating the embedding client on lines 28 to 30 didn't fail: the first request to the service did, and the service answered 404 (Not Found).

What a 404 from embeddings means. The troubleshooting list on Microsoft's page Generate embeddings with Azure OpenAI: For a 404 response, confirm that the endpoint includes /openai/v1/ and that model contains a valid deployment name. The deployment name was right: the same name works in the fix below. The endpoint was the project's, https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp, not a /openai/v1/ endpoint.

Which endpoint serves embeddings. Microsoft's page on Foundry SDKs and endpoints answers it directly: Use the OpenAI SDK endpoint for generating embeddings. The project endpoint used by the Foundry SDK doesn't currently route embedding requests. Its table gives that endpoint as https://<resource-name>.openai.azure.com/openai/v1, and adds that A Foundry resource provides the Foundry endpoints listed in the table. The embeddings need the same resource's other endpoint, not another resource.

Why It Happens​

GetProjectOpenAIClient() returns an OpenAI client whose requests go to the Foundry project endpoint. It hands out an EmbeddingClient without complaint, because that's the OpenAI library's ordinary embedding client, but the project endpoint doesn't route embedding requests, so the first request comes back 404 (Not Found). Chat requests through the same client work, which makes the mistake easy to make.

The Fix​

Create the EmbeddingClient yourself, on the resource's Azure OpenAI endpoint, the way Microsoft's embeddings page does, and keep the project's client for the chat model. Both sign in with the same Azure CLI account, so the app now creates one credential and uses it twice:

Program.cs (the first lines)
using System.ClientModel.Primitives;
using System.Numerics.Tensors;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Embeddings;

AzureCliCredential credential = new();

var openAI = new AIProjectClient(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
credential)
.GetProjectOpenAIClient();
Program.cs (the embeddings)
// An embedding model turns text into a list of numbers, a vector. Texts with similar meanings get similar vectors.
// Embeddings go to the resource's Azure OpenAI endpoint: the project endpoint doesn't route embedding requests.
// This constructor is experimental in the OpenAI library (OPENAI001), so its API can still change.
#pragma warning disable OPENAI001
EmbeddingClient embeddingClient = new(
model: "text-embedding-3-small",
authenticationPolicy: new BearerTokenPolicy(credential, "https://ai.azure.com/.default"),
options: new OpenAIClientOptions { Endpoint = new Uri("https://foundry-devblogs-exp.openai.azure.com/openai/v1/") });
#pragma warning restore OPENAI001

IEmbeddingGenerator<string, Embedding<float>> embeddings = embeddingClient.AsIEmbeddingGenerator();

Signing in to this endpoint with Microsoft Entra ID needs the Cognitive Services OpenAI User role on the resource, which Microsoft's embeddings page lists as a prerequisite. My account already had it.

After the Fix​

Terminal
dotnet run
Output
Q: Can I use a flash when I take photos?
Found: Photography (0.54), Cloakroom and lockers (0.08)
A: No, flash photography is not allowed. **Source: Photography** — https://example.com/guide/photography
223 input tokens

Q: I'm 70. How much is my ticket if I buy it online?
Found: Tickets and prices (0.49), Accessibility (0.16)
A: Your ticket costs **€7 online** (€9 for visitors over 65, minus €2 online discount). **Source: [Tickets and prices](https://example.com/guide/tickets).**
217 input tokens

Q: Is there a café in the museum?
Found: Opening hours (0.44), Photography (0.32)
A: I don’t know; the provided [Opening hours](https://example.com/guide/opening-hours) and [Photography](https://example.com/guide/photography) pages do not mention a café.
223 input tokens

macOS-style terminal window titled Terminal — MuseumGuide showing dotnet run after the fix: for each of three visitor questions, the two guide pages the search found with their scores, the answer and the input tokens. Flash photography is not allowed, a 70-year-old pays 7 euros online, and the agent doesn't know about a café because no page mentions one.

The app embedded the guide when it started and answered all three questions. Each Found line comes from the search: the two pages whose embeddings were closest to the question, with their similarity scores, such as Photography (0.54) for the question about flash. No page mentions a café, so the agent said it doesn't know instead of guessing.

Common Mistakes​

MistakeWhat happensDo this instead
Getting the embedding client from GetProjectOpenAIClient()Service request failed. Status: 404 (Not Found) at the first embedding requestCreate an EmbeddingClient on the resource's /openai/v1/ endpoint
Leaving /openai/v1/ out of the resource endpointMicrosoft's troubleshooting list names it as a cause of a 404Use https://<resource-name>.openai.azure.com/openai/v1/
Putting the model's name where the deployment name goesThe same list names it as the other cause of a 404Use your deployment's name in model

Troubleshooting​

SymptomLikely causeFix
Service request failed. Status: 404 (Not Found) from EmbeddingClient.GenerateEmbeddingsAsyncThe request went to the Foundry project endpointCreate the client on the resource's /openai/v1/ endpoint
error OPENAI001 after switching to an EmbeddingClient with a BearerTokenPolicyThat constructor is experimentalSuppress OPENAI001 around that statement
A 403 response from the embeddings endpointYour account lacks the role the endpoint needsMicrosoft's troubleshooting list says to confirm the Cognitive Services OpenAI User role on the resource

FAQ​

Why does the project's client work for chat but not for embeddings?​

The project endpoint serves the chat model's requests, and the agent's answers above came through it. Microsoft's documentation says it doesn't currently route embedding requests, so embeddings need the resource's OpenAI endpoint.

Do I need another Foundry resource for embeddings?​

No. The project endpoint and the /openai/v1/ endpoint belong to the same resource: here foundry-devblogs-exp on services.ai.azure.com for the project and on openai.azure.com for embeddings.

Why did it fail at startup and not at the first question?​

The app embeds the guide's pages when it starts, on line 33, before it asks anything. That was the first embedding request, so that's where the 404 came.

Conclusion​

Service request failed. Status: 404 (Not Found) from EmbeddingClient.GenerateEmbeddingsAsync, with a client from GetProjectOpenAIClient(), means the embedding request went to the Foundry project endpoint, which doesn't route embedding requests. Create the EmbeddingClient on the same resource's /openai/v1/ endpoint with a BearerTokenPolicy, keep the project's client for chat, and the app embeds its documents and answers.

Additional Resources​