Repository navigation
Description
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.
- The 404 Case: If we set
ImageGenerateParams.Modelto a canonical name (e.g.,gpt-image-1.5), the SDK hitsPOST /images/generations. Azure returns 404 DeploymentNotFound because it requires the deployment name in the URL path. - The 400 Case: If we set
ImageGenerateParams.Modelto 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 (likegpt-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:
- The
modelfield is stripped from the JSON body (as Azure image REST API does not require it). - The
modelfield 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:82path := "images/generations"
-
Model Field Duality: The
Modelfield 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:1189Model ImageModel `json:"model,omitzero"`
-
Middleware Logic: The Azure middleware (likely in
azure/azure.go) uses themodelfield 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.
- Discussion Link: https://learn.microsoft.com/en-us/answers/questions/5847418/i-cannot-perform-image-generation-with-model-gpt-i?comment=question&translated=false#newest-question-comment
- Expert Consensus: Microsoft staff confirmed that while the REST API is healthy, the
openai-goSDK's request-shaping creates a mismatch:"There is currently no supported configuration in openai-go/v3 that simultaneously forces deployment‑scoped routing for images and omits or neutralizes the model field in the request body."
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.
Activity