Azure OpenAI Target adapter for Waken — routes waken Events to an Azure-hosted OpenAI deployment.
Project description
waken-azure-openai
An Azure OpenAI Target adapter for
Waken — "nginx for AI agents." Routes
waken Events to an Azure-hosted OpenAI deployment's Chat Completions API
and returns the result as a waken Response.
This is a separate package from
waken-openai, not a thin
wrapper around it, because Azure OpenAI has a genuinely different
auth/configuration shape — an endpoint URL, a deployment name, and a dated
API version, instead of just an API key — and (as of this writing) only
documents/supports this configuration shape for the Chat Completions API,
not the Responses API waken-openai uses. See "Design notes" below.
Install
pip install waken-azure-openai
Usage
from waken import Runtime
from waken_azure_openai import AzureOpenAIAdapter
runtime = Runtime()
runtime.target("azure-openai", AzureOpenAIAdapter(deployment="my-gpt4-deployment"))
runtime.run()
Three things need to be set, either as constructor arguments or as environment variables:
| Constructor argument | Environment variable | What it is |
|---|---|---|
azure_endpoint |
AZURE_OPENAI_ENDPOINT |
Your Azure OpenAI resource's endpoint, e.g. https://my-resource.openai.azure.com |
api_key |
AZURE_OPENAI_API_KEY |
The resource's API key |
api_version |
AZURE_OPENAI_API_VERSION |
A dated Azure OpenAI API version, e.g. 2024-10-21; defaults to that same GA version if unset |
deployment is the name you gave the model deployment in the Azure
Portal — not an OpenAI model id. This is a distinct and commonly-confused
concept worth spelling out: on Azure, you don't call a model by a name like
"gpt-4.1" directly. You first create a deployment of some underlying
model inside your Azure OpenAI resource and give that deployment its own
name (e.g. "my-gpt4-deployment"), and every API call addresses that
deployment name — Azure looks up which model actually serves it from the
deployment's own configuration. That's why this adapter's constructor
parameter is named deployment, not model: passing an OpenAI model id
here (AzureOpenAIAdapter(deployment="gpt-4.1")) will fail unless you
happen to have named your deployment exactly that.
Any other keyword the openai SDK's AsyncAzureOpenAI client accepts is
forwarded straight through, e.g. azure_ad_token_provider=... to
authenticate via Microsoft Entra ID instead of a static API key:
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
runtime.target(
"azure-openai",
AzureOpenAIAdapter(
deployment="my-gpt4-deployment",
azure_ad_token_provider=get_bearer_token_provider(
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
),
),
)
(get_bearer_token_provider returns a plain sync callable; AsyncAzureOpenAI
accepts either a sync or async callable for azure_ad_token_provider and
awaits it only if it returns an awaitable — confirmed from the installed
SDK's _get_azure_ad_token, not assumed.)
Sessions
Like waken-mistral and waken-cohere (and unlike waken-openai or
Claude, which have a server-side resumable session id), the Chat
Completions API this adapter calls is stateless — it expects the full
conversation history resent on every call. So AzureOpenAIAdapter maps a
waken session_id to a plain, growing list of {"role": ..., "content": ...} messages, appends the new user prompt and the assistant's reply to
that list on every turn, and resends the whole thing each time. History is
kept client-side, in this process's memory only — there's no
persistence layer, and it's lost on restart. An Event with no
session_id sends a fresh one-message list each call and is never stored.
Design notes
Building this adapter meant checking the real openai SDK and Azure's own
current docs rather than assuming parity with waken-openai — worth
recording here since it drove the design:
- The
openaipackage (same PyPI package as vanilla OpenAI) ships anAsyncAzureOpenAIclient alongsideAsyncOpenAI. Its constructor already falls back toAZURE_OPENAI_ENDPOINT/AZURE_OPENAI_API_KEYwhenazure_endpoint/api_keyaren't passed — this adapter forwardsNonestraight through rather than re-implementing that lookup. api_versionis the exception: the SDK's own automatic fallback readsOPENAI_API_VERSION, notAZURE_OPENAI_API_VERSION— despite the latter being what nearly every Azure OpenAI tutorial, the Portal's own code samples, LangChain, and Semantic Kernel all use. This adapter resolvesAZURE_OPENAI_API_VERSIONitself and always passes an explicitapi_version=to the client, so that the more common env var name actually works.- Azure's currently-documented Python pattern for the Responses API
(
client.responses.create(...)) uses a plainOpenAI/AsyncOpenAIclient pointed at a.../openai/v1/base URL — notAzureOpenAI/AsyncAzureOpenAIwith a datedapi_version. Confirmed by reading the installed SDK'sopenai/lib/azure.py(its URL-rewriting only special-cases/chat/completionsand similar endpoints for deployment-scoped routing, not/responses) and by cross-checking Microsoft's own current docs, where everyresponses.create(...)example uses the.../openai/v1/+ plain-client shape and everyAzureOpenAI(azure_endpoint=..., api_version=...)example callschat.completions.create(...). Since this task's whole reason for existing is the endpoint+deployment+api-version auth shape, this adapter is built on Chat Completions rather than forcing the Responses API's session-id pattern through a client shape that doesn't actually route it correctly on Azure. 2024-10-21is used as the defaultapi_versionbecause it's Azure OpenAI's latest generally-available (non-preview) API release as of this writing.
Development
git clone https://github.com/WakenHQ/waken-azure-openai
cd waken-azure-openai
pip install -e ".[dev]"
pytest
Tests mock openai.AsyncAzureOpenAI entirely — no API key, endpoint, or
network access needed to run the suite.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file waken_azure_openai-0.1.0.tar.gz.
File metadata
- Download URL: waken_azure_openai-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2efe2ce3065cb4d0a9f45b7fd9f91599d9c2c9fea0b6f66e36f67da8306b44b3
|
|
| MD5 |
9c1aba92fd4f2ed460c601491cc358f9
|
|
| BLAKE2b-256 |
a7dac2aa4a67257a800dbc03ec8cfc6a3a70efa9d37d3b639e5d7367fcbfc62f
|
Provenance
The following attestation bundles were made for waken_azure_openai-0.1.0.tar.gz:
Publisher:
publish.yml on WakenHQ/waken-azure-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waken_azure_openai-0.1.0.tar.gz -
Subject digest:
2efe2ce3065cb4d0a9f45b7fd9f91599d9c2c9fea0b6f66e36f67da8306b44b3 - Sigstore transparency entry: 2082012501
- Sigstore integration time:
-
Permalink:
WakenHQ/waken-azure-openai@a2d2c4e8048f0f4470c99d644b7600165e76297c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/WakenHQ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a2d2c4e8048f0f4470c99d644b7600165e76297c -
Trigger Event:
push
-
Statement type:
File details
Details for the file waken_azure_openai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: waken_azure_openai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
241130f406cdcb244ff70c32e891a521798763dbbd106083c583eaf885960177
|
|
| MD5 |
b8030a822b3cd0152d91fdfc8bad1475
|
|
| BLAKE2b-256 |
6d7f6758c14c84fb87843864d46d3ddca275bb7211e3ce15179eb3d2eb87edb2
|
Provenance
The following attestation bundles were made for waken_azure_openai-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on WakenHQ/waken-azure-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waken_azure_openai-0.1.0-py3-none-any.whl -
Subject digest:
241130f406cdcb244ff70c32e891a521798763dbbd106083c583eaf885960177 - Sigstore transparency entry: 2082012512
- Sigstore integration time:
-
Permalink:
WakenHQ/waken-azure-openai@a2d2c4e8048f0f4470c99d644b7600165e76297c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/WakenHQ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a2d2c4e8048f0f4470c99d644b7600165e76297c -
Trigger Event:
push
-
Statement type: