How to Set Up a Grounded Bing Search Agent in Azure AI Foundry and Use It via API

:blue_book: Overview

This article provides step-by-step guidance on how to:

  1. Create a Grounding with Bing Search resource in Azure.
  2. Connect it to an Azure AI Foundry Agent.
  3. Interact with the grounded agent programmatically using REST APIs (Threads, Messages, Runs).

Once configured, your agent will be able to use Bing Search results to provide accurate, grounded, citation-based answers.

:wrench: Part 1 — Configure Bing Grounding in Azure

Step 1: Create a “Grounding with Bing Search” Resource

  1. Open the Azure Portal.

  2. In the search bar, type “Grounding with Bing Search”.

  3. Select Create.

  4. Provide the required details:

    • Subscription
    • Resource Group (recommended: same as your AI agent)
    • Name for the grounding resource
  5. Choose a pricing tier.

  6. Click Review + create → Create.

Your Bing grounding resource is now deployed.

Step 2: Add the Grounding Tool to Your Agent

  1. Open the Azure AI Foundry portal.
  2. Navigate to Agents.
  3. Select your agent.
  4. On the right-side Setup panel, select Knowledge.
  5. Click Add.
  6. From the tool list, choose Grounding with Bing Search.
  7. When prompted, click Add connection.
  8. Select the Bing grounding resource created in Step 1.
  9. Click Add connection to finalize.

Your agent is now configured to perform Bing-grounded search queries.

:globe_with_meridians: Part 2 — Interacting with the Grounded Agent Using REST APIs

Azure Agents follow a Threads → Messages → Runs model.

Before sending requests, authenticate using Azure CLI.

Step 3: Authenticate and Obtain an Access Token

1. Log in to Azure

az login

2. Fetch access token for Azure AI Foundry

az account get-access-token --resource 'https://ai.azure.com' | jq -r .accessToken | tr -d '"'

Use this token as your Bearer token in all API calls.

:test_tube: Part 3 — Using the API

Below are the endpoints to create a thread, add a message, run it, and retrieve the output.

Use your actual project name and agent resource name in URLs:

https://<your-agent-resource>.services.ai.azure.com/api/projects/<project>

Step 4: Create a Thread

curl --request POST \
 --url 'https://search-agent-resource.services.ai.azure.com/api/projects/search-agent/threads?api-version=2025-05-01' \
 -H "Authorization: Bearer <bearer>" \
 -H "Content-Type: application/json" \
 -d ''

Example Response

{
  "id": "thread_oNLMlAS6UEely1dYXnZobrA5",
  "object": "thread",
  "created_at": 1763553651,
  "metadata": {},
  "tool_resources": {}
}

Step 5: Add a User Message to the Thread

curl --request POST \
 --url 'https://search-agent-resource.services.ai.azure.com/api/projects/search-agent/threads/thread_oNLMlAS6UEely1dYXnZobrA5/messages?api-version=2025-05-01' \
 -H "Authorization: Bearer <bearer>" \
 -H "Content-Type: application/json" \
 -d '{
     "role": "user",
     "content": "Get me the latest news on the stock market"
   }'

Step 6: Run the Thread (Trigger the Agent)

curl --request POST \
 --url 'https://search-agent-resource.services.ai.azure.com/api/projects/search-agent/threads/thread_oNLMlAS6UEely1dYXnZobrA5/runs?api-version=2025-05-01' \
 -H "Authorization: Bearer <bearer>" \
 -d '{
   "assistant_id": "asst_DG0ojfEdfF85p8NEkkr8Lkqn"
 }'

The response shows:

  • run ID
  • status
  • grounding tool configuration attached to the agent

Step 7: Check Run Status

curl --request GET \
 --url 'https://search-agent-resource.services.ai.azure.com/api/projects/search-agent/threads/thread_oNLMlAS6UEely1dYXnZobrA5/runs/run_SlmNzVexTdclCDm5Q2UXchvv?api-version=2025-05-01' \
 -H "Authorization: Bearer <bearer>"

Example response:

"status": "completed"

Step 8: Retrieve the Agent’s Output

curl --request GET \
 --url 'https://search-agent-resource.services.ai.azure.com/api/projects/search-agent/threads/thread_oNLMlAS6UEely1dYXnZobrA5/messages?api-version=2025-05-01' \
 -H "Authorization: Bearer <bearer>"

This returns:

  • user message(s)
  • assistant response
  • grounded citations from Bing Search

:white_check_mark: Summary

You have now:

:heavy_check_mark: Created a Grounding with Bing Search resource
:heavy_check_mark: Connected it to your Azure AI Foundry agent
:heavy_check_mark: Used authentication and REST API calls to:

  • Create a thread
  • Add user messages
  • Run the agent
  • Retrieve grounded responses with citations

Your agent can now answer any factual queries using real-time Bing Search grounding.

1 Like