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

# 构建实现上下文

> 在 token 预算内为应用或代理组装带有来源引用的技术上下文。



## OpenAPI

````yaml zh/index-openapi.json POST /v1/context
openapi: 3.0.1
info:
  title: Mintlify Index API
  description: 为应用和代理搜索并获取技术文档与 Web 上下文。
  version: 1.0.0
servers:
  - url: https://leaves.mintlify.com/api/universal-search
security:
  - bearerAuth: []
paths:
  /v1/context:
    post:
      summary: 构建实现上下文
      description: >-
        搜索 Mintlify Index，并在 token
        预算内组装带有来源引用的内容。当应用或代理需要通过一次请求获取可直接使用的上下文时，请使用此端点。
      operationId: buildIndexContext
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextRequest'
            example:
              query: 我应该如何在 Next.js 16 中配置缓存？
              product: Next.js
              format: txt
              tokenBudget: 3000
      responses:
        '200':
          description: 上下文组装成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextResponse'
              example:
                requestId: 7f2ab8d1-3bea-4a29-bc51-c05a8d3a3e3c
                query: 我应该如何在 Next.js 16 中配置缓存？
                response: >-
                  ### 缓存与重新验证


                  来源：https://nextjs.org/docs/app/getting-started/caching-and-revalidating


                  使用本指南中介绍的当前缓存 API。


                  --------------------------------
                resultsCount: 3
                outputTokens: 1842
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ContextRequest:
      type: object
      additionalProperties: false
      required:
        - query
        - format
      properties:
        query:
          type: string
          minLength: 1
          description: 要研究的实现问题。
        product:
          type: string
          minLength: 1
          description: 用作额外检索提示的产品或公司名称。
        format:
          type: string
          enum:
            - txt
            - json
          description: '`response` 字符串的格式。`txt` 返回 Markdown 部分，`json` 返回包含结果项目的序列化 JSON 对象。'
        includeDomains:
          type: array
          minItems: 1
          items:
            type: string
            minLength: 1
          description: 要纳入检索的域名。
        excludeDomains:
          type: array
          minItems: 1
          items:
            type: string
            minLength: 1
          description: 要从检索中排除的域名。
        tokenBudget:
          type: integer
          minimum: 1
          maximum: 6000
          default: 3000
          description: 输出 token 的最大数量。
    ContextResponse:
      type: object
      additionalProperties: false
      required:
        - requestId
        - query
        - response
        - resultsCount
        - outputTokens
      properties:
        requestId:
          type: string
          description: 请求的唯一标识符。
        query:
          type: string
          description: 请求中的原始查询。
        response:
          type: string
          description: >-
            组装后的来源内容。对于 `txt` 请求，该值为 Markdown；对于 `json` 请求，该值为序列化 JSON。当没有内容适合
            token 预算时，该字符串可以为空。
        resultsCount:
          type: integer
          minimum: 0
          description: 响应中包含的来源片段数量。
        outputTokens:
          type: integer
          minimum: 0
          description: 组装后响应中的 token 数量。
    Error:
      type: object
      additionalProperties: false
      required:
        - error
      properties:
        error:
          type: string
          description: 错误消息。
  responses:
    BadRequest:
      description: 请求正文无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 请求正文无效
    Unauthorized:
      description: API key 缺失或无效，或组织无权访问 Index REST API。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 未授权
    Forbidden:
      description: API key 不允许该请求 IP。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 该 API key 不允许此 IP 地址
    RateLimited:
      description: 组织超出速率限制。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 超出速率限制。请稍后重试
    InternalError:
      description: Index 无法完成请求。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Mintlify Index API 密钥
      description: 带有 `mint_us_` 前缀的 Mintlify Index API 密钥。

````

## Related topics

- [自动化概览](/docs/zh/automations/index.md)
- [AI 助手](/docs/zh/assistant/index.md)
- [GitHub](/docs/zh/deploy/github.md)
