Solution skill
Python: Function Calling Error when Using APIM Managed Azure OpenAI
Complete solution
Fixes 400 'unable to parse' errors on function calling through APIM-managed Azure OpenAI by setting estimate-prompt-tokens to false in the azure-openai-token-limit policy. Use when Python Semantic Kernel function calls fail behind Azure APIM. Not for direct-to-Azure OpenAI calls or non-APIM gateways.
Fix first: in your APIM instance, open the azure-openai-token-limit policy and set estimate-prompt-tokens to false. Two reporters confirmed function calling started working right after the change.
400 unable to parse- Open the azure-openai-token-limit policy in Azure APIM.
- Set estimate-prompt-tokens to false. When it is true, APIM estimates tokens from the prompt schema and throws the 400; when false, tokens are calculated from actual model usage.
- Retry the function call. Expected: the call succeeds and returns tool calls with no 400.
When to use: function calling fails with a 400 through Azure APIM, in Python Semantic Kernel or similar setups.
When not to use: calls that go straight to Azure OpenAI without APIM, or 400s that come from somewhere other than the token-limit policy.
Compatibility: Semantic Kernel (Python), Azure API Management, Azure OpenAI.
Variants:
- "apim function calling 400 unable to parse"
- "azure-openai-token-limit policy function calling"
- "estimate-prompt-tokens false"
Root cause: with estimate-prompt-tokens set to true, APIM tries to estimate tokens from the function-calling prompt schema and fails to parse it, so the request is rejected before it ever reaches the model.
Edge cases: if other APIs on the same APIM instance depend on estimated tokens, scope the change to the function-calling API instead of flipping it globally.
Evidence
In gh:microsoft/semantic-kernel#10182 (https://github.com/microsoft/semantic-kernel/issues/10182), the reporter ran into this: Reported in Semantic Kernel: Python: Function Calling Error when Using APIM Managed Azure OpenAI. The verified resolution: [fbinotto (commenter)]: If function calling fails with a 400 through Azure APIM, check the azure-openai-token-limit policy: estimate-prompt-tokens must be set to false. When true, APIM estimates tokens from the prompt schema and throws a 400 unable to parse; when false, tokens are calculated from actual model usage. Both reporters confirmed function calling works after the change.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_3z9pPakcR1-PTe9HotWAWQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Python: Function Calling Error when Using APIM Managed Azure OpenAI <span>— Vectle</span></a>