Skip to content

Grep File

$ llamacloud-prod beta:retrieval grep
POST/api/v1/retrieval/files/grep

Grep within a file’s parsed content using a regex pattern.

ParametersExpand Collapse
--file-id: string

Body param: ID of the file to grep.

--index-id: string

Body param: ID of the index the file belongs to.

--pattern: string

Body param: Regex pattern to search for.

--organization-id: optional string

Query param

--project-id: optional string

Query param

--context-chars: optional number

Body param: Number of characters of context to include before and after the matched pattern in the content field of the response

--page-size: optional number

Body param: The maximum number of items to return. The service may return fewer than this value. If unspecified, a default page size will be used. The maximum value is typically 1000; values above this will be coerced to the maximum.

--page-token: optional string

Body param: A page token, received from a previous list call. Provide this to retrieve the subsequent page.

ReturnsExpand Collapse
FileGrepResult: object { items, next_page_token, total_size }

Paginated grep results for a file.

items: array of object { content, end_char, start_char }

The list of items.

content: string

Matched text content.

end_char: number

End character offset of the match.

start_char: number

Start character offset of the match.

next_page_token: optional string

A token, which can be sent as page_token to retrieve the next page. If this field is omitted, there are no subsequent pages.

total_size: optional number

The total number of items available. This is only populated when specifically requested. The value may be an estimate and can be used for display purposes only.

Grep File

llamacloud-prod beta:retrieval grep \
  --api-key 'My API Key' \
  --file-id file_id \
  --index-id idx-abc123 \
  --pattern 'revenue|profit'
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
Returns Examples
{
  "items": [
    {
      "content": "content",
      "end_char": 0,
      "start_char": 0
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
Note for AI agents: this documentation is built for programmatic access. - Overview of all docs: https://developers.llamaindex.ai/llms.txt - Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md - Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters. - A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/python/shared/mcp/