Azure / Azure/LogicAppsUX

[Bug] New Agent workflows with APIM GenAI Gateway connection always call OpenAI instead of APIM — agentModelType ignored

Open
#8,972 1 comment 0 reactions 0 assignees View on GitHub
Agentic bug Connections needs-investigation priority:high
Dominant language
TypeScript
Stars
111
Forks
109
Avg merge
1d 23h
Merged PRs (30d)
20

Description

### Severity

P1 - Critical (Blocking production)

### Describe the Bug with repro steps

New Agent workflows in a Standard Logic App fail to use the configured APIM GenAI Gateway connection. The runtime ignores agentModelType: "APIMGenAIGateway" and deploymentId in the workflow JSON, and instead calls a default OpenAI endpoint with model gpt-5.4-nano.

Existing workflows created earlier with the exact same connection (agent-9) and identical parameters continue to work. Only newly created workflows are affected.

This is related to #7359 but that issue focuses on the Portal designer UX. This issue is about the runtime not binding the APIM connection for new workflows regardless of creation method.

Steps to reproduce:

Have a Standard Logic App with an existing APIM GenAI Gateway agent connection (e.g. agent-9) in connections.json
Have at least one working agent workflow using that connection (e.g. Workflow-A)
Create a new workflow (Workflow-B) with an Agent action referencing the same connection — same agentModelType: "APIMGenAIGateway", same deploymentId, same modelConfigurations
Deploy via Kudu VFS (PUT to /api/vfs/site/wwwroot/Workflow-B/workflow.json)
Workflow shows as Healthy in management API
Trigger the workflow → fails with: AgentLoopChatCompletionFailed: HTTP 403 (invalid_request_error: model_not_found) Project proj_sdCJNhnL3iOTiRngXQ88Z1jB does not have access to model gpt-5.4-nano
Trigger Workflow-A (same connection, same parameters) → succeeds
Also tried (all failed with same error):

Creating the workflow in Portal designer first, then updating JSON via Kudu
Adding agentInstructions field
Adding workflow-draft.json alongside workflow.json
Restarting the Logic App
Re-saving from Portal designer
Key evidence that the runtime ignores the APIM connection for new workflows
The error references an OpenAI project ID (proj_sdCJNhnL3iOTiRngXQ88Z1jB) and model (gpt-5.4-nano). Our APIM endpoint does NOT route to OpenAI — verified by direct curl:

APIM endpoint with correct model → Returns correct Claude response ✓
APIM endpoint with gpt-5.4-nano → Returns Gemini response (APIM backend fallback), NOT a 403 ✓
The 403 with proj_sdCJNhnL3iOTiRngXQ88Z1jB comes from an OpenAI endpoint that is NOT configured anywhere in our app settings or connections. The runtime is using an internal default OpenAI connection instead of the configured APIM connection.

Stack trace from runtime logs

System.ClientModel.ClientResultException: HTTP 403 (invalid_request_error: model_not_found)
Project `proj_sdCJNhnL3iOTiRngXQ88Z1jB` does not have access to model `gpt-5.4-nano`
at OpenAI.ClientPipelineExtensions.ProcessMessageAsync(...)
at OpenAI.Chat.ChatClient.CompleteChatAsync(...)
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.RunRequestAsync[T](...)
The runtime uses OpenAI.Chat.ChatClient (OpenAI C# SDK) directly instead of routing through the configured APIM endpoint.

Portal designer issue
When creating a new Agent action in the Portal designer, there is no UI option to select "APIM Gen AI Gateway" as the Agent Model Source — only "Azure OpenAI" and "Foundry Agent Service" are available. This forces agentModelType: "AzureOpenAI" in the generated JSON.

When the workflow already has an APIM connection (agent-9) and the Portal forces agentModelType: "AzureOpenAI", saving produces: AgentConnectionResourceIdInvalid: 'agent-9' agent connection is invalid. The 'resourceId' parameter value isn't a valid Azure OpenAI resource ID.

### What type of Logic App Is this happening in?

Standard (Portal)

### Are you experiencing a regression?

_No response_

### Which operating system are you using?

Windows

### Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

### Workflow JSON

```json
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"actions": {
"Test_agent": {
"type": "Agent",
"inputs": {
"parameters": {
"deploymentId": "claude-haiku-4-5",
"messages": [
{
"role": "system",
"content": "Generate a fun fact in one sentence."
}
],
"agentModelType": "APIMGenAIGateway",
"agentInstructions": "Generate a fun fact."
},
"modelConfigurations": {
"model1": {
"referenceName": "agent-9"
}
}
},
"tools": {},
"runAfter": {},
"limit": {
"count": 100
}
},
"Response": {
"type": "Response",
"kind": "Http",
"inputs": {
"statusCode": 200,
"body": "@outputs('Test_agent')?['lastAssistantMessage']"
},
"runAfter": {
"Test_agent": ["SUCCEEDED"]
}
}
},
"outputs": {},
"triggers": {
"When_an_HTTP_request_is_received": {
"type": "Request",
"kind": "Http"
}
}
},
"kind": "stateful"
}
```

### Screenshots or Videos

_No response_

### Environment

Region: Germany West Central
Runtime extension version: 1.160.21.0
Connection type: APIM GenAI Gateway (Key-based auth)
Working workflows: 2 (created before this issue appeared)
Failing workflows: 3 (any newly created workflow)

### Additional context

Correlation IDs from failed runs:

95569967-015d-4d89-88a3-1a6ee21b01c4

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.