---
title: "Retrieve Context from AI Assistant"
method: POST
path: "/ai/1/aiassistants/{assistantId}/retrieve-context"
tags: ["ai-hub", "ai-assistants"]
---

# Retrieve Context from AI Assistant

`POST /ai/1/aiassistants/{assistantId}/retrieve-context`

## 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}/retrieve-context`
- 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

Retrieves the most relevant context chunks from an AI assistant's knowledge base for a given message.<br/><br/>This endpoint performs a semantic search over the assistant's indexed documents and returns the most relevant text segments (top k chunks). You can specify how many chunks to return and optionally enable re-ranking for more accurate results.<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

- 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34RetrieveContextRequest: AI Assistant retrieve context request with optional retrieval parameters.
  - `message` string, required: User message to retrieve context for.
  - `k` integer: Number of context chunks to return. Overrides the assistant's default K value. Use this to get more or fewer context chunks.
  - `reRankK` integer: Enables re-ranking for improved precision. When set, retrieves max(k, reRankK) chunks initially, then uses a cross-encoder to return the top K most relevant results.
  - `useSharedHistory` boolean: Flag to indicate whether to use shared conversation history.
  - `sessionId` string: Session ID to maintain context across multiple queries.

## Response `200`

Context retrieved successfully

- 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34RetrieveContextApiResponse
  - `contexts` 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34ContextNode[], required: List of retrieved context nodes.
    - `node` 2a53d681c9399f766b0cfff54e0469d04419b36fc1603e6db03e69cc8ad55f34NodeDetails, required: Context node details.
      - `id` string, required: Node ID.
      - `text` string, required: Text content.
      - `metadata` object: Metadata information.
      - `startCharIdx` integer: Start character index.
      - `endCharIdx` integer: End character index.
    - `score` number, double, required: Relevance score for the node.

## 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)
