Skip to main content

Fixed: OPENAI001 'OpenAI.Embeddings.EmbeddingClient.EmbeddingClient(string, System.ClientModel.Primitives.AuthenticationPolicy, OpenAI.OpenAIClientOptions)' is for evaluation purposes only

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

I created an OpenAI EmbeddingClient that signs in with my Azure CLI account, the way Microsoft's embeddings documentation shows, and the build failed: error OPENAI001: 'OpenAI.Embeddings.EmbeddingClient.EmbeddingClient(string, System.ClientModel.Primitives.AuthenticationPolicy, OpenAI.OpenAIClientOptions)' is for evaluation purposes only and is subject to change or removal in future updates. That constructor is experimental in the OpenAI .NET library. Microsoft's sample has a line that disables OPENAI001, and it was the line I had left out.

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). When it starts, it turns each of the guide's five pages into an embedding, a list of numbers that stands for the text's meaning. Before every answer, it finds the pages whose embeddings are closest to the question's and gives them to the model.

The embeddings have to come from the Foundry resource's Azure OpenAI endpoint, because the project endpoint doesn't route embedding requests (Fixed: "Service request failed. Status: 404 (Not Found)" Generating Embeddings from a Microsoft Foundry Project). So I followed the C# code on Microsoft's page Generate embeddings with Azure OpenAI: an EmbeddingClient for my text-embedding-3-small deployment, on the resource's /openai/v1/ endpoint, signed in with a BearerTokenPolicy. I copied the client, but not the line above it that disables OPENAI001.

The project references these packages:

MuseumGuide.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.21.0" />
<PackageReference Include="Microsoft.Agents.AI.Foundry" Version="1.28.0-preview.261106.1" />
<PackageReference Include="System.Numerics.Tensors" Version="10.0.15" />
</ItemGroup>

</Project>

The OpenAI .NET library isn't referenced directly: it comes into the project with Microsoft.Agents.AI.Foundry, a preview package. The top of Program.cs brings in the namespaces and creates one credential for the whole app:

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();

And the embedding client, as it was:

Program.cs (the embedding client, as it was)
// 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.
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/") });

IEmbeddingGenerator<string, Embedding<float>> embeddings = embeddingClient.AsIEmbeddingGenerator();
  • model is the name of the embedding model deployment.
  • authenticationPolicy signs every request with a Microsoft Entra ID token for https://ai.azure.com/.default, which AzureCliCredential gets from the Azure CLI's signed-in account. No API key is involved.
  • options points the client at the resource's OpenAI v1 endpoint.
  • AsIEmbeddingGenerator() wraps the client in the IEmbeddingGenerator interface that the rest of the app uses.

What I Expected​

A successful build. The client is the one in Microsoft's sample, with my endpoint and deployment name.

What I Got​

Terminal
dotnet run
Output
/Users/you/source/MuseumGuide/Program.cs(34,35): error OPENAI001: 'OpenAI.Embeddings.EmbeddingClient.EmbeddingClient(string, System.ClientModel.Primitives.AuthenticationPolicy, OpenAI.OpenAIClientOptions)' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

The build failed. Fix the build errors and run again.

macOS-style terminal window titled Terminal — MuseumGuide showing dotnet run stopping with error OPENAI001 at line 34, column 35 of Program.cs: OpenAI.Embeddings.EmbeddingClient.EmbeddingClient(string, System.ClientModel.Primitives.AuthenticationPolicy, OpenAI.OpenAIClientOptions) is for evaluation purposes only and is subject to change or removal in future updates, followed by The build failed. Fix the build errors and run again.

dotnet run builds the project before it runs it, and the build stopped at this one error, so the app never started.

What I Checked​

Where the error points. Line 34, column 35 is the new( of EmbeddingClient embeddingClient = new(...): the constructor call. The error names one overload, the constructor that takes a model name, an AuthenticationPolicy and OpenAIClientOptions. The type name at the start of the same line and the call to AsIEmbeddingGenerator() reported nothing. Only this way of creating the client is flagged.

Microsoft's sample. The C# code on Generate embeddings with Azure OpenAI has #pragma warning disable OPENAI001 right after its using lines. Then it creates the client with the same constructor and the same three named arguments: model, authenticationPolicy and options. The C# sample for the /openai/v1 endpoint on Microsoft's page about Foundry SDKs and endpoints, which creates a different client, disables OPENAI001 as well.

What .NET says about experimental APIs. The .NET documentation on preview APIs: When building against an experimental API, the compiler produces an error. And: To express consent to using an experimental API, you suppress the specific diagnostic. OPENAI001 is the OpenAI library's ID, and it uses that one ID for other APIs too, such as its Responses client (Fixed: "error OPENAI001: 'OpenAI.Responses.ResponsesClient' is for evaluation purposes only …").

How far Microsoft's line reaches. The sample's #pragma warning disable OPENAI001 has no restore. The C# reference: If there's no restore in the file, the warnings restore to their default state at the first line of any later files in the same compilation. So in the sample, OPENAI001 is off from that line to the end of the file. A restore straight after the statement limits it to the one constructor call.

Why It Happens​

The OpenAI .NET library marks the EmbeddingClient constructor that takes an AuthenticationPolicy as experimental, with the diagnostic ID OPENAI001. The compiler reports every call to it as an error until you suppress that ID. Microsoft's documented way to sign in to the embeddings endpoint with Microsoft Entra ID, a BearerTokenPolicy, goes through exactly that constructor.

The Fix​

Put #pragma warning disable OPENAI001 before the statement that creates the client and #pragma warning restore OPENAI001 after it, with a comment that says why:

Program.cs (the embedding client)
// 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();
  • #pragma warning disable OPENAI001 stops the compiler from reporting OPENAI001, from the next line on.
  • #pragma warning restore OPENAI001 turns it back on after the constructor call, so another experimental OpenAI API added later still gets its own error.
  • The comment says what was accepted and why, for the next person who reads the file.

The .NET documentation recommends the project's <NoWarn> property for this kind of consent. That works too, but it accepts OPENAI001 in every file of the project, for every OpenAI API that reports 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. (Guide: [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). **Page:** [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** and **Photography** pages do not mention a café.
223 input tokens

macOS-style terminal window titled Terminal — MuseumGuide showing dotnet run after the fix: three visitor questions, each with the two guide pages the search found and 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 guide page mentions one.

The build passed, the app embedded the guide's pages when it started, and it answered all three questions. Each Found line shows the two pages whose embeddings were closest to the question, with their similarity scores. No page mentions a café, so for that question the agent said it doesn't know.

Common Mistakes​

MistakeWhat happensDo this instead
Copying Microsoft's client code without its #pragma warning disable OPENAI001 lineerror OPENAI001 on the EmbeddingClient constructorCopy that line too, and add a restore after the statement
Switching to an API key to avoid the errorYou have a long-lived secret to store and protectKeep Microsoft Entra ID and suppress OPENAI001
#pragma warning disable without an IDEvery warning after it in the file is hidden tooName the ID: #pragma warning disable OPENAI001

Troubleshooting​

SymptomLikely causeFix
error OPENAI001 for the EmbeddingClient constructorThe constructor that takes an AuthenticationPolicy is experimentalWrap the statement in #pragma warning disable OPENAI001 and restore
Service request failed. Status: 404 (Not Found) the first time the app generates embeddingsThe client points at the Foundry project endpointUse the resource's /openai/v1/ endpoint: the 404 fix
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​

Does a newer OpenAI package remove the error?​

No. With the OpenAI package 2.15.0 referenced directly, the same constructor still reports OPENAI001 without the pragma.

Why not use an API key instead?​

The embeddings endpoint accepts one, but Microsoft's embeddings documentation recommends Microsoft Entra ID: Microsoft Entra ID is recommended because it avoids storing long-lived credentials. Two pragma lines cost less than a key you have to store and protect.

Is it safe to use an experimental constructor?​

It works, but its shape can change in a later version of the OpenAI library, and suppressing OPENAI001 is how you accept that. Creating the client in one place, as here, keeps a future change to one statement.

Conclusion​

error OPENAI001 on EmbeddingClient(string, AuthenticationPolicy, OpenAIClientOptions) means the OpenAI library's constructor for signing in with a token is experimental. Microsoft's embeddings sample disables OPENAI001 for it. Wrap the statement that creates the client in #pragma warning disable OPENAI001 and #pragma warning restore OPENAI001, with a comment that says why, and the client builds and embeds without an API key.

Additional Resources​