can1357/oh-my-pi · error
Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL
Error message
Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or configure model.baseUrl.
What it means
resolveAzureOpenAiBaseUrl cannot determine the Azure OpenAI endpoint for compaction. The base URL must come from AZURE_OPENAI_BASE_URL, from AZURE_OPENAI_RESOURCE_NAME (used to build https://<name>.openai.azure.com/openai/v1), or from the model's configured baseUrl. If all three are absent, compaction cannot know where to send requests and throws.
Source
Thrown at packages/agent/src/compaction/compaction-v2-streaming.ts:164
if (normalizedBase.endsWith("/v1")) return `${normalizedBase}/responses`;
return `${normalizedBase}/v1/responses`;
}
function resolveOpenAiCodexResponsesEndpoint(baseUrl: string | undefined): string {
const rawBase = baseUrl && baseUrl.trim().length > 0 ? baseUrl : CODEX_BASE_URL;
const normalizedBase = rawBase.replace(/\/+$/, "");
if (normalizedBase.endsWith("/codex/responses")) return normalizedBase;
if (normalizedBase.endsWith("/codex")) return `${normalizedBase}/responses`;
return `${normalizedBase}/codex/responses`;
}
function resolveAzureOpenAiBaseUrl(model: Model): string {
const baseUrl = $env.AZURE_OPENAI_BASE_URL?.trim() || undefined;
const resourceName = $env.AZURE_OPENAI_RESOURCE_NAME;
const resolvedBaseUrl =
baseUrl ?? (resourceName ? `https://${resourceName}.openai.azure.com/openai/v1` : undefined) ?? model.baseUrl;
if (!resolvedBaseUrl) {
throw new Error(
"Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or configure model.baseUrl.",
);
}
return resolvedBaseUrl.replace(/\/+$/, "");
}
function appendAzureApiVersion(endpoint: string): string {
if (/[?&]api-version=/.test(endpoint)) return endpoint;
const separator = endpoint.includes("?") ? "&" : "?";
return `${endpoint}${separator}api-version=${encodeURIComponent($env.AZURE_OPENAI_API_VERSION || DEFAULT_AZURE_API_VERSION)}`;
}
function resolveCompactionV2Model(model: Model): string {
const requestModel = model.remoteCompaction?.model ?? model.requestModelId ?? model.id;
if (compactionV2Api(model) !== "azure-openai-responses") return requestModel;
const mappedDeployment = parseAzureDeploymentNameMap($env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(requestModel);
return mappedDeployment ?? requestModel;
}View on GitHub (pinned to 9690622007)
Solutions
- Set AZURE_OPENAI_BASE_URL to your Azure endpoint (e.g. https://my-res.openai.azure.com/openai/v1)
- Alternatively set AZURE_OPENAI_RESOURCE_NAME to your Azure resource name so the URL is constructed
- Or pass/patch model.baseUrl on the Model object when constructing the provider/model config
- Verify the env vars are actually visible to the process ($env) — check CI secrets, .env loading, and container env
Example fix
// before "AZURE_OPENAI_API_KEY": "..." // no base URL configured // after "AZURE_OPENAI_BASE_URL": "https://my-resource.openai.azure.com/openai/v1", "AZURE_OPENAI_API_KEY": "..."
Defensive patterns
Strategy: validation
Validate before calling
if (
!process.env.AZURE_OPENAI_BASE_URL &&
!process.env.AZURE_OPENAI_RESOURCE_NAME &&
!model.baseUrl
) {
throw new Error(
"Azure compaction needs AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME or model.baseUrl",
);
} Type guard
function hasAzureBaseUrl(model: Model): boolean {
return Boolean(
process.env.AZURE_OPENAI_BASE_URL?.trim() ||
process.env.AZURE_OPENAI_RESOURCE_NAME ||
model.baseUrl,
);
} Prevention
- Set AZURE_OPENAI_BASE_URL (or RESOURCE_NAME) wherever the agent runs: local, CI, containers
- Fail fast at startup with an env check for Azure deployments
- Configure baseUrl on the Model itself when embedding in SDKs where env vars are unreliable
When it happens
Trigger: Calling V2 compaction (or getCompactionV2Endpoint) for a model hosted on Azure OpenAI when neither AZURE_OPENAI_BASE_URL nor AZURE_OPENAI_RESOURCE_NAME is set in the environment and the Model object has no baseUrl.
Common situations: Azure deployment configured only via api-key + deployment name without endpoint env vars; env vars present in local shell but missing in CI/serverless runtime; model created programmatically without baseUrl; typo'd env var names.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL
- Invalid GITLAB_REDIRECT_URI: ${raw}
- GITLAB_REDIRECT_URI must use http:// or https://, got: ${raw
- GITLAB_REDIRECT_URI loopback callbacks must use http://, got
- OMP_AUTH_BROKER_URL must be set (or `auth.broker.url` in con
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/d0587c34ea7e1137.
Report an issue: GitHub.