How to include Api Subscription key of Custom Question Answer in Azure Bot Service Web App

Sonali Vaghela 0 Reputation points
2025-03-05T12:47:56.0733333+00:00

In Azure AI Bot Service, I have added Custom Question Answer Service Endpoint to the Bot Service Message Endpoint.
But I am unable to find where to add subscription key to the bot.

Also, Direct link to create a bot from Custom Question Answer deployment not working.
Any suggestions?

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
907 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Prashanth Veeragoni 1,185 Reputation points Microsoft External Staff
    2025-03-06T04:04:03.6833333+00:00

    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.


  2. Sonali Vaghela 0 Reputation points
    2025-03-07T07:04:02.9233333+00:00

    Hi @Prashanth Veeragoni

    Thanks for your reply.
    Currently I am not creating bot from code. I am using Azure AI Bot service.

    In the creation, I have already entered the My Custom question answer message endpoint. But I am unable to find where to enter it's subscription key.

    I have already tested the APIs of custom QnA in postman and it's working fine.

    There is no application setting thing that you have suggested.
    User's image

    I have gone through below steps to create bot.

    Go to Azure Bot -> Create New -> Type of App (Multi Tenant) -> Review & Create

    After creating in the configuration section, I am writing message endpoint.
    While clicking on "Test in Web Chat", it is throwing "Unauthorized" error.

    Am I doing anything wrong in that?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.