---
title: "Query AI Assistant by ID"
method: POST
path: "/ai/1/aiassistants/{assistantId}/query"
tags: ["ai-hub", "ai-assistants"]
---

# Query AI Assistant by ID

`POST /ai/1/aiassistants/{assistantId}/query`

## Request

- Base URL: `https://api.infobip.com` (the document declares no server; this is the origin it was published from)
- URL: `https://api.infobip.com/ai/1/aiassistants/{assistantId}/query`
- Auth: one of:
  - OAuth 2
    - Client credentials
    - Token URL: `https://api.infobip.com/auth/1/oauth2/token`
  - API key in header `Authorization`
  - API key in header `Authorization`
  - HTTP basic

Forwards a message from a user to a specific AI assistant identified by its unique ID and returns the assistant's response.<br/><br/>This endpoint performs a semantic search over an AI assistant's indexed documents based on configured guidelines. It then generates a response using the LLM connected to the assistant.<br/><br/>The "use shared history" feature allowing an AI assistant to utilize the agent's conversation history, is only available if used together with [Infobip AI agents](https://www.infobip.com/docs/ai-agents).

## Path parameters

- `assistantId` string, required

## Request body

- 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34SimpleAiAssistantQuery: Simple AI Assistant query with just a message.
  - `message` string, required: User message an AI assistant receives.
  - `useSharedHistory` boolean: Indicates whether to use shared conversation history. Can only be used with [Infobip AI agents](https://www.infobip.com/docs/ai-agents).
  - `sessionId` string: Session ID to maintain context across multiple queries.
  - `returnContexts` boolean: Flag to indicate whether to return the contexts used in generating the response.

## Response `200`

AI Assistant response retrieved successfully

- 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34QueryAiAssistantApiResponse
  - `response` string, required: Ai Assistant answer.
  - `context` 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34QueryAiAssistantApiResponseContext: Ai Assistant context used for generating the answer.
    - `originalContexts` 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34QueryAiAssistantApiResponseContextChunk[]: Ai Assistant contexts before reranking.
      - `text` string, required: The text content of the context chunk retrieved from the assistant's knowledge base.
      - `filename` string, required: The name of the source file from which this context chunk was extracted.
    - `rerankedContexts` 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34QueryAiAssistantApiResponseContextChunk[]: Ai Assistant contexts after reranking.
      - `text` string, required: The text content of the context chunk retrieved from the assistant's knowledge base.
      - `filename` string, required: The name of the source file from which this context chunk was extracted.

## Other responses

- `400`: Bad request
- `401`: Unauthorized
- `403`: Forbidden
- `404`: Assistant not found
- `429`: Too Many Requests
- `500`: Internal Server Error

---

[API](https://skmtc.dev/infobip/apis/infobip-openapi-specification.md) - [All operations](https://skmtc.dev/infobip/apis/infobip-openapi-specification/llms.txt) - [OpenAPI document](https://skmtc.dev/infobip/apis/infobip-openapi-specification/revisions/9dcbbaf902de?raw)
