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

2 answers

Sort by: Most helpful
  1. Karnam Venkata Rajeswari 3,255 Reputation points Microsoft External Staff Moderator
    2026-05-19T20:17:14.8133333+00:00

    Hello Dawid Smolenski,

    Welcome to Microsoft Q&A .Thank you for reaching out to us.

    The observed behavior aligns with the current implementation of the Azure OpenAI v1

    The GetInputTokenCountAsync method internally attempts to call the following endpoint:

    POST /v1/responses/input_tokens
    

    When using the Azure OpenAI v1 compatibility endpoint:

    https://<resource>.openai.azure.com/openai/v1/
    

    this specific route is not currently supported on the v1 compatibility endpoint, resulting in 404 - Unknown request URL

    This confirms that the issue is not related to authentication, deployment configuration, SDK initialization or request formatting. Instead, it is caused by a service capability limitation, where the SDK helper method relies on an endpoint that is not exposed.

    The Azure OpenAI v1 compatibility endpoint supports core Responses API operations, such as model inference (response generation). However, not all helper or auxiliary endpoints are available.

    Specifically:

    • The /v1/responses endpoint for inference is supported
    • The /v1/responses/input_tokens helper endpoint is not currently supported
    • SDK methods such as GetInputTokenCountAsync depend on this route and therefore fail

    This highlights a feature availability gap between SDK capabilities and the service endpoint rather than any misconfiguration.

    Please check if the following workarounds help-

    1. Avoid using GetInputTokenCountAsync on the v1 endpoint
      1. This method depends on an unsupported route
      2. Calls to this method will consistently return 404 in this setup
    2. Continue using supported Responses API operations Ensure standard configuration: Endpoint format -
         https://<resource>.openai.azure.com/openai/v1/
      
      1. Model value matches a valid deployment name
      2. Supported APIs (such as response generation) are used for inference

    As troubleshooting validation -

    To confirm correct isolation of the issue:

    • If response generation calls (for example, CreateResponseAsync) succeed
    • And only GetInputTokenCountAsync fails with 404

    This confirms:

    • Endpoint and deployment configuration are correct
    • The issue is isolated to the unsupported /responses/input_tokens route

    The following references might be helpful , please check them out

    Please let us know if the response was helpful

    Thank you

    Was this answer helpful?

    0 comments No comments

  2. 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.