> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useparagon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Read Segment Context

> Read the text before and after a passage returned by search.

Use this endpoint when a search result looks relevant and you need more of the surrounding text. Pass the `pointer` from a search result passage.

Use `direction` to choose which side to read: `around` (default), `before`, or `after`. Use `maxTokens` to limit the size of the response. It defaults to 2000 and cannot exceed 32000. At least one chunk is always returned, even if that chunk alone is larger than `maxTokens`.

The response includes `prev` and `next` pointers for the neighboring chunks, or `null` at the start or end of the document. Pass either one back to this endpoint to keep reading in that direction.

If the pointer doesn't exist or the user doesn't have access to it, the request returns a `404` with the error code `RESOURCE_NOT_FOUND`. Run a new search to get a fresh pointer.

```javascript theme={null}
const response = await fetch(
  `https://agentos.useparagon.com/api/context/projects/${projectId}/segments/${pointer}/context?direction=around&maxTokens=2000&identity=${encodeURIComponent("user@example.com")}`,
  {
    headers: { Authorization: `Bearer ${paragonUserToken}` },
  },
);
```


## OpenAPI

````yaml agent-os/openapi/context.json GET /api/context/projects/{projectId}/segments/{pointer}/context
openapi: 3.1.0
info:
  title: Agent OS Context API
  version: 1.0.0
  description: Search your users' synced content and read the text around a search result.
servers:
  - url: https://agentos.useparagon.com
    description: Production US Cloud
  - url: https://agentos.eu.paragon.so
    description: Production EU Cloud
security:
  - bearerAuth: []
paths:
  /api/context/projects/{projectId}/segments/{pointer}/context:
    get:
      summary: Read Segment Context
      operationId: readSegmentContext
      parameters:
        - $ref: '#/components/parameters/ProjectId'
        - name: pointer
          in: path
          required: true
          schema:
            type: string
          description: The pointer from a passage in a search result.
        - name: direction
          in: query
          description: >-
            Which side of the pointer to read: around it, before it, or after
            it.
          schema:
            type: string
            enum:
              - around
              - before
              - after
            default: around
        - name: maxTokens
          in: query
          description: >-
            The maximum number of tokens to return. At least one chunk is always
            returned, even if it is larger than this limit.
          schema:
            type: integer
            minimum: 1
            maximum: 32000
            default: 2000
        - name: identity
          in: query
          schema:
            type: string
            maxLength: 1024
          description: >-
            The account whose access applies, used on every source. Unlike
            search, this endpoint accepts a single string only.
        - name: email
          in: query
          description: Deprecated. Use identity instead.
          schema:
            type: string
            maxLength: 1024
            deprecated: true
      responses:
        '200':
          description: The text around the pointer.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SegmentContextResponse'
              example:
                id: 6f1c0b2e-1a2b-4c3d-8e9f-0a1b2c3d4e5f.rec_1
                text: |-
                  # Q2 roadmap
                  The Q2 roadmap covers launch dates.
                prev: null
                next: chk_next
                tokenBudget:
                  returnedTokens: 18
                tokenizer: o200k_base
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '403':
          $ref: '#/components/responses/Error'
        '404':
          $ref: '#/components/responses/Error'
components:
  parameters:
    ProjectId:
      name: projectId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: >-
        Your Paragon Project ID. Must match the Project ID in your Paragon User
        Token.
  schemas:
    SegmentContextResponse:
      type: object
      required:
        - id
        - text
        - prev
        - next
        - tokenBudget
        - tokenizer
      properties:
        id:
          type: string
          description: Unique ID for the record, in the format {syncId}.{recordId}.
        text:
          type: string
          description: The text around the pointer.
        prev:
          oneOf:
            - type: string
            - type: 'null'
          description: >-
            Pointer to the chunk before this text, or null if this is the start
            of the record.
        next:
          oneOf:
            - type: string
            - type: 'null'
          description: >-
            Pointer to the chunk after this text, or null if this is the end of
            the record.
        tokenBudget:
          type: object
          required:
            - returnedTokens
          description: How much text was returned.
          properties:
            returnedTokens:
              type: integer
              description: The number of tokens in text.
        tokenizer:
          type: string
          enum:
            - o200k_base
          description: The tokenizer used to count tokens.
    ErrorEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - hint
            - retryable
            - requestId
          properties:
            code:
              type: string
              description: >-
                A stable error code you can handle in your code, such as
                REQUEST_INVALID.
            message:
              type: string
              description: A human-readable description of what went wrong.
            hint:
              type: string
              description: Suggested next step to resolve the error.
            retryable:
              type: boolean
              description: Whether retrying the same request may succeed.
            retryAfterMs:
              type: integer
              description: >-
                How long to wait before retrying, in milliseconds. Only present
                when retryable is true.
            requestId:
              type: string
              description: Include this ID when contacting Paragon support about a request.
            details:
              type: array
              description: >-
                Present on validation errors. Lists the fields that failed
                validation.
              items:
                type: object
                required:
                  - field
                  - issue
                properties:
                  field:
                    type: string
                    description: The field that failed validation.
                  issue:
                    type: string
                    description: What was wrong with the field.
  responses:
    Error:
      description: The request failed. See the error object for details.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Your [Paragon User
        Token](/getting-started/installing-the-connect-sdk#setup) (JWT), which
        you can generate using your project's signing keys.

````