Skip to content

bug: Azure middleware fails to route Image Generation correctly (404/400 mismatch) #641

Description

@AbhAy120204

Bug Report

Import path of package in question
github.com/openai/openai-go/v3/azure

SDK version
v3.30.0 (Latest)

Go version
go version go1.25.0 linux/amd64

What happened?
When using the openai-go SDK with an Azure OpenAI endpoint for image generation, it is impossible to construct a request that Azure accepts. There is a conflict between how the SDK uses the Model field for routing and how Azure validates that same field in the JSON body.

  1. The 404 Case: If we set ImageGenerateParams.Model to a canonical name (e.g., gpt-image-1.5), the SDK hits POST /images/generations. Azure returns 404 DeploymentNotFound because it requires the deployment name in the URL path.
  2. The 400 Case: If we set ImageGenerateParams.Model to the Azure Deployment Name to trigger the Azure middleware's path rewriting, the URL becomes correct (/openai/deployments/<name>/images/generations), but the JSON body now contains "model": "<deployment-name>". Azure's image service rejects this with a 400 Bad Request, stating it only supports canonical names (like gpt-image-1.5) in the body.

What did you expect or want to happen?
The Azure middleware should support a configuration where the Deployment Name is injected into the URL path, but either:

  1. The model field is stripped from the JSON body (as Azure image REST API does not require it).
  2. The model field in the body remains a canonical identifier while a separate option provides the deployment name for the URL.

How can we reproduce it?

// 1. Initialize with Azure middleware
client := openai.NewClient(
    azure.WithEndpoint("https://<your-resource>.openai.azure.com/", "<your-deployment-name>"),
    azure.WithAPIKey("..."),
)

// 2. Attempt generation
// If Model = "gpt-image-1.5" -> 404 (Path is wrong)
// If Model = "<deployment-name>" -> 400 (Body is wrong)
_, err := client.Images.Generate(ctx, openai.ImageGenerateParams{
    Prompt: openai.F("a cat"),
    Model:  openai.F("<deployment-name>"), 
})

Technical References (Internal Bottlenecks)
The issue is a result of the high-level service implementation and the Azure middleware's dependency on the model field:

  • Hardcoded Path: The image service hardcodes the relative path, which the Azure middleware must intercept and rewrite:

    vendor/github.com/openai/openai-go/v3/image.go:82

    path := "images/generations"
  • Model Field Duality: The Model field is used both for JSON serialization and for the Azure middleware's routing logic. There is currently no way to decouple them:

    vendor/github.com/openai/openai-go/v3/image.go:1189

    Model ImageModel `json:"model,omitzero"`
  • Middleware Logic: The Azure middleware (likely in azure/azure.go) uses the model field to build the deployment path but does not modify the request body to remove the field that causes the 400 error in Azure.

Reference to Official Confirmation
This issue has been vetted and confirmed by Microsoft support staff as a limitation of the current SDK abstraction when interfacing with Azure's REST contract for images.

Anything we should know about your environment.
This occurs on Azure OpenAI GPT-Image-1.5 deployments. Direct REST calls work when the deployment is in the URL and the model field is absent from the body, proving the service works and the SDK's request construction is the bottleneck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryIssue concerns handwritten SDK/library runtime behavior.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions