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

# Completion

> Provides answering based on document content.

## 文档问答

**URL**: `/v1/chat/completion`\
**方法**: `POST`\
**描述**: 提供基于文档内容的问答服务。

### 请求参数

| 参数名          | 类型          | 描述                                                                                                                              |
| ------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------- |
| query        | str         | 问题或查询内容。                                                                                                                        |
| doc\_ids     | array\[str] | 指定文档 ID 列表，可选，默认为空数组。                                                                                                           |
| mode         | str         | 响应模式，支持 `concise`, `comprehensive`, `deepresearch`。                                                                             |
| categories   | array       | 文档类别（默认不包含 `files`），可选值有 `financials`，`transcripts`，`reports`（国内研报），`global_research`（外资研报），`filings`，`news`，`socials`，`files`。 |
| institutions | array       | 指定机构筛选，如 `Morgan Stanley`，`Seeking Alpha`。*暂未支持*                                                                                |
| market       | str         | 市场区域，默认包括所有市场。可选值有 `sz`, `sh`, `hk`, `us`。                                                                                      |
| symbol       | str         | 股票代码筛选，如 `SH:000001`，`HK:00700`，`US:AAPL`。                                                                                      |
| tags         | dict        | 标签数组。                                                                                                                           |
|     key      | str         | 标签类型（如 `industry`, `company`, `person`, `event`）。                                                                               |
|     value    | array       | 标签内容数组。                                                                                                                         |
| session\_id  | str         | 会话 ID，用于跟踪问答上下文。                                                                                                                |
| stream       | bool        | 是否使用流式传输响应，默认值为 `true`，当前只支持 `true`。                                                                                            |

**说明：**

* 当 categories 为 `files` 时，可以通过指定 `tags` 参数来筛选上传的文件（上传时制定了相应的 `tags`）。

### 响应参数

| 参数名         | 类型   | 描述       |
| ----------- | ---- | -------- |
| type        | str  | 响应的类型。   |
| message\_id | str  | 消息唯一 ID。 |
| message     | str  | 问答内容。    |
| extra       | dict | 额外信息。    |

### 请求示例

**cURL**

```bash theme={null}
curl -X POST https://api.reportify.cn/v1/chat/completion \
-H "Authorization: Bearer 447460****09c9" \
-H "Content-Type: application/json" \
-d '{
    "query": "What are the latest trends in AI?",
    "doc_ids": ["1046895208953942016"],
    "mode": "research",
    "session_id": "session123",
    "stream": true
}'
```

**Python 示例**

```python theme={null}
import requests

url = "https://api.reportify.cn/v1/chat/completion"
headers = {
    "Authorization": "Bearer 447460****09c9",
    "Content-Type": "application/json"
}
payload = {
    "query": "What are the latest trends in AI?",
    "doc_ids": ["1046895208953942016"],
    "mode": "research",
    "session_id": "session123",
    "stream": True
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

### 响应示例

```json theme={null}
data: {"type": "questions", "message_id": "10035660298823686", "message": "", "extra": {"questions": ["特斯拉最近的营收和利润情况如何？", "特斯拉最近的交付量和生产量如何？", "特斯拉最近在市场上的表现如何？"], "in_steps": false}}

data: {"type": "start", "message_id": "10035660298823686", "message": "特斯拉最近业绩表现", "extra": {}}

data: {"type": "info", "message_id": "10035660298823686", "message": "", "extra": {"tool": {"key": "", "query": "特斯拉最近的营收和利润情况如何？\n特斯拉最近的交付量和生产量如何？\n特斯拉最近在市场上的表现如何？", "question": "特斯拉最近的营收和利润情况如何？\n特斯拉最近的交付量和生产量如何？\n特斯拉最近在市场上的表现如何？"}}}

data: {"type": "info", "message_id": "10035660298823686", "message": "", "extra": {"sources": [{"type": "text", "summary": "", "doc": {"doc_id": "1046895208953942016", "title": "Tesla(TSLA) - 2024 Q3 - Quarterly Report", "url": "https://reportify.cn/financials/1046895208953942016"}}]}}

data: {"type": "answer", "message_id": "10035660298823686", "message": "特斯拉最近业绩表现", "extra": {"sources": [{"type": "table", "summary": "", "doc": {"doc_id": "1046895208953942016", "title": "Tesla(TSLA) - 2024 Q3 - Quarterly Report", "url": "https://reportify.cn/financials/1046895208953942016"}}]}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "特斯拉", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "2", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "0", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "2", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "4", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "年", "extra": {}}

......
......
......

data: {"type": "stream", "message_id": "10035660298823686", "message": "渗透率", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "[", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "3", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "7", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "]", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "。", "extra": {}}

data: {"type": "stream", "message_id": "10035660298823686", "message": "", "extra": {}}

data: {"type": "end", "message_id": "10035660298823686", "message": "特斯拉2024年第三季度业绩表现如下：\n- **营收情况**：\n    - **总营收**：第三季度总营收为251.8亿美元，同比增长8%。其中，汽车业务营收228.06亿美元，同比增长5%；能源生成和存储业务营收23.76亿美元，同比增长52%；服务及其他业务营收27.9亿美元，同比增长29%[2][9]。\n![](https://duplik-1252068037.cos.ap-beijing.myqcloud.com/duplik/447460783945158/478331591190662/604690073731654/element/117.jpg)\n![](https://duplik-1252068037.cos.ap-beijing.myqcloud.com/duplik/447460783945158/478331591190662/604690073731654/element/95.jpg)\n    - **汽车业务细分**：汽车销售营收188.31亿美元，同比增长1%，主要因Model 3和Model Y现金交付量增加以及Cybertruck交付量上升，同时车辆平均售价降低和产品组合变化部分抵消了增长；汽车监管信贷营收7.39亿美元，同比增长33%，受北美地区信贷需求推动；汽车租赁营收4.46亿美元，同比下降9%，主要因直接销售型租赁交付量降低和租赁买断减少[2][11][18]。\n    - **能源生成和存储业务**：营收增长主要由于Megapack和Powerwall的部署增加[36]。\n    - **服务及其他业务**：营收增长主要源于非保修维护服务、碰撞修复收入、二手车收入、付费超级充电收入、保险服务收入和零部件销售收入的增加[12]。\n- **利润情况**：\n    - **净利润**：第三季度净利润为21.83亿美元，同比增长16.3%。归属于普通股股东的净利润为21.67亿美元，同比增长17.0%[4][6]。\n![](https://duplik-1252068037.cos.ap-beijing.myqcloud.com/duplik/447460783945158/478331591190662/604690073731654/element/9.jpg)\n![](https://duplik-1252068037.cos.ap-beijing.myqcloud.com/duplik/447460783945158/478331591190662/604690073731654/element/6.jpg)\n    - **利润率**：总汽车业务的毛利率从2023年第三季度的18.7%上升至20.4年第三季度的20.1%，主要得益于单位车辆平均综合成本降低、FSD收入和监管信贷收入增加，部分被车辆平均售价降低所抵消[31]。\n- **现金流情况**：\n    - **经营活动现金流**：九个月内提供的经营活动净现金为101.09亿美元，较2023年同期的88.86亿美元增加12.2亿美元，主要因净经营资产和负债的有利变化，部分被净收入（不含非现金费用、收益和损失）的减少所抵消[7][17]。\n- **生产与交付情况**：\n    - **汽车生产与交付**：2024年前三季度生产约131.4万辆消费类汽车，交付约129.4万辆。专注于盈利性增长，包括利用现有工厂和生产线推出新产品、降低成本、提高产能和交付能力等[37]。\n    - **能源存储产品部署**：2024年前三季度部署了20.41 GWh的能源存储产品，专注于提高生产和市场渗透率[37]。", "extra": {"return_mode": 1, "agent_mode": 2}}
```


## OpenAPI

````yaml POST /v1/chat/completion
openapi: 3.1.0
info:
  title: Reportify API
  version: 1.0.0
  description: API documentation for Reportify's document management and search services.
servers:
  - url: https://api.reportify.cn
    description: Production server
security:
  - BearerAuth: []
paths:
  /v1/chat/completion:
    post:
      tags:
        - openapi-chat
      summary: Chat Completion
      description: Provides answering based on document content.
      operationId: chat_completion_reportify_api_v1_chat_completion_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAIChatCompletionRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAIChatCompletionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - BearerAuth: []
components:
  schemas:
    OAIChatCompletionRequest:
      properties:
        query:
          type: string
          title: Query
        folder_ids:
          items:
            type: string
          type: array
          title: Folder Ids
          default: []
        doc_ids:
          items:
            type: string
          type: array
          title: Doc Ids
          default: []
        categories:
          items:
            $ref: '#/components/schemas/OAIDocCategory'
          type: array
          default: []
        markets:
          items:
            $ref: '#/components/schemas/OAIMarket'
          type: array
          default: []
        institutions:
          items:
            type: string
          type: array
          title: Institutions
          default: []
        symbols:
          items:
            type: string
          type: array
          title: Symbols
          default: []
        tags:
          additionalProperties:
            items: {}
            type: array
          type: object
          title: Tags
        start_date:
          type: string
          title: Start Date
        end_date:
          type: string
          title: End Date
        min_score:
          type: number
          title: Min Score
        extended_filters:
          items:
            type: object
          type: array
          title: Extended Filters
        mode:
          allOf:
            - $ref: '#/components/schemas/OAIChatMode'
          default: concise
        session_id:
          type: string
          title: Session Id
          default: ''
        stream:
          type: boolean
          title: Stream
          default: true
      type: object
      required:
        - query
      title: OAIChatCompletionRequest
    OAIChatCompletionResponse:
      properties:
        type:
          type: string
          title: Type
        message_id:
          type: string
          title: Message Id
        message:
          type: string
          title: Message
        extra:
          type: object
          title: Extra
          default: {}
      type: object
      required:
        - type
        - message_id
        - message
      title: OAIChatCompletionResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    OAIDocCategory:
      type: string
      enum:
        - financials
        - transcripts
        - reports
        - news
        - files
        - filings
        - socials
        - global_research
      title: OAIDocCategory
      description: An enumeration.
    OAIMarket:
      type: string
      enum:
        - cn
        - hk
        - us
      title: OAIMarket
      description: An enumeration.
    OAIChatMode:
      type: string
      enum:
        - concise
        - comprehensive
        - deepresearch
      title: OAIChatMode
      description: An enumeration.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Enter your Bearer token

````