Skip to content

[Python] Support using keyless auth for Azure OpenAI #216

Closed

Description

@pamelafox

We try to use keyless auth for all our samples, so if I were to use TypeChat in them, it'd need to support keyless auth, aka this constructor:

    openai_client = AsyncAzureOpenAI(
        api_version=api_version,
        azure_endpoint=endpoint,
        azure_ad_token_provider=token_provider,
    )

I'd be happy to just pass in my whole client to typechat as I typically already have it configured correctly for other uses in my app. Trying to match environment variables will be a pain since we have existing environment variable names that arent the same as yours.

Activity

  1. pamelafox commented on Apr 23, 2024

    @pamelafox
    MemberAuthor

    Keyless auth is now a strict requirement for all our samples, so this a blocker for us.

  2. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    The TypeScript implemenation supports this...we should port that do the Python implementation.

  3. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    /typechat draft

  4. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    TypeChat: Draft prepared; owner or maintainer input is still needed before work acceptance.

    Owner request | Run and preview

    Operational receipt only. This comment does not publish draft text, accept work, authorize implementation, or approve merging.

  5. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    I think we should modify the public API so that callers can provide a configured client/token provider. We should be careful to maintain backward compatibility.

  6. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    /typechat draft

  7. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    TypeChat: Draft prepared; owner or maintainer input is still needed before work acceptance.

    Owner request | Run and preview

    Operational receipt only. This comment does not publish draft text, accept work, authorize implementation, or approve merging.

  8. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    /typechat publish 13208841811:36d43ed7696cc2e2abf27c7d86dc2ae443d724c13dd789ed6004dc7d60b1b56a

  9. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    /typechat reply

  10. github-actions commented on Nov 3, 2026

    @github-actions
    Contributor

    You can keep your existing configuration names: TypeChatJsonTranslator accepts a TypeChatLanguageModel, the interface with an asynchronous complete method that returns response text in Success or an error in Failure. An application-side adapter can wrap your configured AsyncAzureOpenAI client and use its keyless authentication, meaning identity tokens instead of a stored API key, while TypeChat retains schema validation and repair. This is a custom adapter path, not direct client injection into the built-in factory.

    The built-in Azure factory is narrower: create_azure_openai_language_model takes a fixed credential string and the full chat-completions URL, including deployment and API version, and creates its own network client. It already sets an authorization header intended for managed identity, but it has no token-provider callback, a function that obtains a current identity token, or parameter for an existing OpenAI client. Its fixed headers do not provide automatic token renewal.

    Would a public token-provider hook with explicit endpoint configuration meet your sample requirements, or do you need direct reuse of your configured AsyncAzureOpenAI client to preserve its other settings? That distinction would help focus an extension to the existing integration while preserving current API-key calls.

    Related contributions: #139, #198, #436, #446.

    Automated response requested by the project owner. This does not accept work or authorize implementation.

  11. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    I think Pamela is requesting a reuse of a configured client so that tokens can be refreshed automatically, etc.

  12. robgruen commented on Nov 3, 2026

    @robgruen
    Contributor

    Draft PR #516 is ready for review.

    It adds two opt-in Python integration paths:

    • A synchronous or asynchronous token provider for the existing Azure OpenAI HTTP factory.
    • An adapter for an already-configured AsyncOpenAI/AsyncAzureOpenAI or compatible async Chat Completions client, preserving application-owned configuration and lifecycle.

    There are no additional TypeChat dependencies or required environment-variable changes. Existing factory arguments, API-key behavior, environment configuration, validation, and repair remain intact.

    Local validation passed: 41 deterministic tests, Pyright with zero errors/warnings, and mocked interoperability/type checks against genuine OpenAI and Azure OpenAI SDK clients. No live model calls or credentials were used.

    The PR remains a draft for human review; no merge is requested.

  13. robgruen commented on Nov 6, 2026

    @robgruen
    Contributor

    #516 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionScope or design nuances need to be discussedLanguage: PythonPertains to the Python implementation of TypeChat.SuggestionNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions