Share via

404 Response when executing GetInputTokenCountAsync with azure endpoint

Dawid Smolenski 0 Reputation points
2026-05-13T16:48:43.24+00:00

Describe the bug

When OpenAIClient is configured with an Azure OpenAI v1 compatibility endpoint (https://xxx.openai.azure.com/openai/v1/), calling GetInputTokenCountAsync throws ClientResultException: HTTP 404 — Unknown request URL: POST /v1/responses/input_tokens. This azure openai endpoint is from the code sample when viewing deployment details on azure foundry.

Steps to reproduce

Steps to reproduce

  1. Construct OpenAIClient with OpenAIClientOptions { Endpoint = new Uri("https://.openai.azure.com") } and an API key.
  2. Get the response client: var responsesClient = openClient.GetResponsesClient();
  3. Build a request body as BinaryContent.
  4. Call await client.GetInputTokenCountAsync(contentType, content);

Code snippets

OpenAIClient openClient = new(
    credential: new ApiKeyCredential(apiKey),
    options: new OpenAIClientOptions()
    {
        Endpoint = new(endpoint),
    });
var responsesClient = openClient.GetResponsesClient();
CreateResponseOptions chatOptions = new()
{
    Model = deploymentName,
    Instructions = "You are a helpful assistant that talks like a pirate."
};
chatOptions.InputItems.Add(ResponseItem.CreateUserMessageItem("Hi, can you help me?"));
chatOptions.InputItems.Add(ResponseItem.CreateAssistantMessageItem("Arrr! Of course, me hearty! What can I do for ye?"));
chatOptions.InputItems.Add(ResponseItem.CreateUserMessageItem("What's the best way to train a parrot?"));
var countRequestBody = JsonSerializer.Serialize(chatOptions);
var response = await responsesClient.GetInputTokenCountAsync(
    "application/json",
    BinaryContent.Create(BinaryData.FromString(countRequestBody)));

Windows

.NET version

10

Library version

2.10.0

Azure OpenAI in Foundry Models

1 answer

Sort by: Most helpful
  1. AI answer

    2026-05-13T16:48:58.5666667+00:00

    GetInputTokenCountAsync is calling the Responses API endpoint /v1/responses/input_tokens. A 404 from an Azure OpenAI v1‑compatibility endpoint means that this specific path is not implemented on that endpoint.

    In Azure AI Foundry / Azure OpenAI today:

    • A 404 for Responses API calls generally indicates that the model/deployment or the path does not match what the resource supports.
    • The v1‑compatibility endpoint (...openai.azure.com/openai/v1/) does not expose every preview feature or helper route; only the documented REST paths are guaranteed to exist.

    So, when OpenAIClient is pointed at https://<resource>.openai.azure.com/openai/v1/, the SDK’s GetInputTokenCountAsync tries to POST to /v1/responses/input_tokens, but the Azure endpoint does not recognize that URL and returns 404 Unknown request URL.

    To resolve this in the current platform behavior:

    1. Do not rely on GetInputTokenCountAsync against the Azure v1‑compatibility endpoint, because the /v1/responses/input_tokens route is not available there.
    2. Use only the supported Azure OpenAI REST/SDK operations for your resource and region, as documented for the Responses API. If token counting is required, implement it client‑side (for example, by using a tokenizer compatible with the target model) instead of calling /v1/responses/input_tokens.
    3. When troubleshooting 404s with Azure OpenAI endpoints, always verify:
      • The endpoint path matches the documented Azure OpenAI pattern (...openai.azure.com/openai/v1/).
      • The model value in the request matches an existing deployment name for that resource.

    If the same client and key work for other Responses API calls (for example, create-response) but only GetInputTokenCountAsync fails with 404, that confirms the issue is the unsupported input_tokens route rather than authentication or deployment configuration.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.