Hi Sonali Vaghela,
Welcome to Microsoft Q&A forum. Thanks for posting your query.
Since your bot is calling the Custom Question Answering (part of Azure AI Search & Language Services), it needs an API key for authentication. The API key should be added to the request headers. Follow these steps:
Option 1: Add Subscription Key in Bot Code (If You Have Code Access)
If you have access to your bot’s code (in a Bot Framework SDK or Web App Bot), include the API key in the HTTP request headers:
import requests
API_ENDPOINT = "https://<your-custom-question-answer-endpoint>/language/:query-knowledgebases"
SUBSCRIPTION_KEY = "your-subscription-key"
headers = {
"Ocp-Apim-Subscription-Key": SUBSCRIPTION_KEY,
"Content-Type": "application/json"
}
data = {
"question": "your question",
"top": 3
}
response = requests.post(API_ENDPOINT, headers=headers, json=data)
print(response.json())
Replace <your-custom-question-answer-endpoint> with your actual Azure Custom Question Answering endpoint.
Option 2: Add API Key in Azure Bot Configuration (If No Code Access):
If you are using Azure Bot Service without direct code access, follow these steps:
Go to Azure Bot Service:
Open Azure Portal → Navigate to Bot Services → Select your bot.
Set the API Key as an Application Setting:
Go to Configuration in your bot's App Service.
Under Application settings, click New application setting.
Add:
Name: QNA_SUBSCRIPTION_KEY
Value: your-subscription-key
Click Save.
Modify Bot Service Endpoint (if required):
Open Bot Service → Settings → Messaging Endpoint.
If using a proxy, ensure it forwards the Ocp-Apim-Subscription-Key header.
Direct Link to Create a Bot from Custom Question Answer Not Working:
If the direct link is not working, try the manual approach:
Step 1: Deploy a Custom Question Answering Service
- Go to Azure AI Services.
- Search for Language Services → Create a Custom Question Answering (CQA) resource.
- Note the endpoint URL and API key (found in Keys & Endpoint).
Step 2: Create a New Bot Manually
- In Azure Portal, go to Bot Services → Click Create.
- Choose Web App Bot or Bot Framework SDK.
- Under Cognitive Services, add the Custom Question Answering endpoint manually.
Final Checks:
Verify that the subscription key is valid from Azure Cognitive Services → Keys & Endpoints.
Use Postman to check if your API is responding correctly.
Check Bot Logs (Application Insights) for request failures.
Hope this helps. Do let us know if you any further queries.
-------------
If this answers your query, do click Accept Answer and Yes for was this answer helpful.
Thank you.