How to configure AzureChatCompletion with APIM URL in Python #8340
-
Hello Team - Can you please help with Python example on how to access Semantic Kernel with APIM URL. I am adding below parameters to AzureChatCompletion but getting error - Access denied due to missing subscription key. Is there any other parameter available to mention Ocp-Apim-SubscriptionKey from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion azure_chat_service= AzureChatCompletion( |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@eavanvalkenburg @moonbox3 - Can you please help with this query |
Beta Was this translation helpful? Give feedback.
-
Hi @nehalakhani there are three things you can try, the first is using the AzureChatCompletion(
api_key=Value of Ocp-Apim-SubscriptionKey
endpoint={apim_url}/deployments/gpt-4o/chat/completions/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview
deployment_name='gpt-4o'
api_version='2024-02-15-preview'
default_headers={'Ocp-Apim-SubscriptionKey': <value>}
} The second is passing in a AsyncAzureOpenAI client directly, after verifying that that passes it in the right way: from openai import AsyncAzureOpenAI
client = AsyncAzureOpenAI(
...
)
AzureChatCompletion(
async_client = client,
...
) The third is changing the setup of APIM to accept the key with a different name, I used to have this setup, but not anymore so I know it can be done, but not sure exactly how, maybe this supplies some ideas: https://github.com/microsoft/AzureOpenAI-with-APIM |
Beta Was this translation helpful? Give feedback.
Hi @nehalakhani there are three things you can try, the first is using the
default_headers
param:The second is passing in a AsyncAzureOpenAI client directly, after verifying that that passes it in the right way:
The third is changing the setup of A…