Skip to content

Infer Azure region from endpoint - #184

Closed
jnu wants to merge 1 commit into
mainfrom
infer-region
Closed

Infer Azure region from endpoint#184
jnu wants to merge 1 commit into
mainfrom
infer-region

Conversation

@jnu

@jnu jnu commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

When the region is not set in the runtime config, it can be inferred from the openai service endpoints. This also solves the issue of having cross-region deployments.

Comment thread bc2/core/common/openai.py
return resource_name.rsplit("-", 1)[-1] or None


class OpenAIConfig(BaseModel):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The _azure_region function may incorrectly extract a region from an Azure OpenAI hostname if the name doesn't contain a hyphen, causing cost estimation to fail.
Severity: MEDIUM

Suggested Fix

The _azure_region function should be updated to handle hostnames without a hyphen. One approach is to return None if rsplit("-", 1) results in a list with only one element, indicating no hyphen was found. Alternatively, the extracted value could be validated against a list of known Azure region names.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: bc2/core/common/openai.py#L634

Potential issue: The `_azure_region` function attempts to infer the Azure region by
splitting the resource hostname on the last hyphen. However, if an Azure OpenAI resource
name does not contain a hyphen (e.g., `myresource.openai.azure.com`), the function will
incorrectly return the entire resource name as the region. This invalid region name is
then used to query the Azure Retail Prices API, which returns no results. Consequently,
the application will raise an `AzurePricingUnavailable` exception, preventing cost
estimation for that resource.

Did we get this right? 👍 / 👎 to inform future reviews.

@jnu jnu closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant