Skip to content

OpenAI provider: detect Azure-shaped OPENAI_BASE_URL and append api-version #374

@rohitg00

Description

@rohitg00

Why

#307 added the universal OpenAI-compatible provider and lists Azure OpenAI in its supported-endpoints table:

Azure OpenAI    https://{resource}.openai.azure.com/openai/deployments/{deployment}

But Azure OpenAI's /chat/completions requires:

  1. An api-version=<YYYY-MM-DD> query parameter on every request (mandatory; the request 400s without it).
  2. The api-key: <key> header instead of Authorization: Bearer <key> (Azure also accepts Bearer when AAD-auth is in use, but the api-key path is the default for key auth).

OpenAIProvider.call() today doesn't add either, so the Azure path in the supported-endpoints table is non-functional as-shipped.

Proposal

In src/providers/openai.ts:

private isAzure(): boolean {
  const url = this.baseURL ?? "";
  return url.includes("openai.azure.com") || url.includes("/openai/deployments/");
}

private buildRequestUrl(path: string): string {
  const base = this.baseURL ?? "https://api.openai.com";
  if (this.isAzure()) {
    const apiVersion = getEnvVar("AZURE_OPENAI_API_VERSION") ?? "2024-08-01-preview";
    return `${base}/chat/completions?api-version=${apiVersion}`;
  }
  return `${base}/v1/chat/completions`;
}

private buildHeaders(): HeadersInit {
  if (this.isAzure()) {
    return { "Content-Type": "application/json", "api-key": this.apiKey };
  }
  return { "Content-Type": "application/json", Authorization: `Bearer ${this.apiKey}` };
}

Note: Azure URLs already include the deployment path, so we append /chat/completions (no /v1/ segment).

Acceptance

  • OPENAI_BASE_URL=https://<resource>.openai.azure.com/openai/deployments/<deployment> + OPENAI_API_KEY=<azure-key> round-trips a summarize call.
  • AZURE_OPENAI_API_VERSION env var documented in README with the default GA value.
  • Non-Azure base URLs (OpenAI, DeepSeek, SiliconFlow, Ollama, vLLM, LM Studio) unaffected — same code path, same Authorization: Bearer header.

Supersedes

Out of scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions