﻿openapi: 3.0.3
info:
  title: 语鲸开放平台 API
  description: |
    语鲸（LingoWhale）开放平台对外数据接口，提供订阅频道文章的分页获取、今日增量、
    单篇详情、频道搜索、订阅/取消订阅、频道列表与追踪频道管理能力。
    支持程序/Agent 自主完成「搜索频道 → 订阅频道 → 拉取文章」闭环。

    ## 认证
    所有接口通过请求头携带应用凭据（在「数据获取 → API 调试」页面的密钥栏获取）：
    - `X-App-ID`: 应用 ID
    - `X-App-Secret`: 应用密钥

    ## 通用响应结构
    所有接口返回统一信封：`{ "code": 0, "message": "...", "data": ... }`，
    `code` 为 0 表示成功；非 0 时 `message` 含错误说明。

    ## 频道限制
    开启频道限制的账号，文章接口只返回「抓取列表」内频道的文章；拉取不在列表中的
    channel_id 返回 403（业务码 40310）。追踪频道受额度上限约束，超限返回 403（40311）。
  version: "2.0.0"
  contact:
    name: 语鲸开放平台
    url: https://open.lingowhale.com

servers:
  - url: https://open.lingowhale.com
    description: 生产环境

security:
  - AppID: []
    AppSecret: []

tags:
  - name: 账号
    description: 列出绑定的语鲸账号（发现 account_id）
  - name: 文章
    description: 文章列表、今日增量、单篇详情
  - name: 频道
    description: 订阅频道列表与追踪频道管理

paths:
  /open-api/v1/accounts:
    get:
      tags: [账号]
      summary: 获取绑定账号列表
      description: |
        列出当前应用绑定的所有语鲸账号,用于发现 account_id。
        其它接口的 account_id 即取自这里;留空(不传 account_id)则聚合全部账号。
      operationId: listAccounts
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        account_id: { type: string, description: 账号 ID,传给其它接口的 account_id 参数 }
                        nickname: { type: string, description: 语鲸账号昵称 }
                        phone: { type: string, description: 脱敏手机号,如 138****1234 }

  /open-api/v1/articles:
    get:
      tags: [文章]
      summary: 获取文章列表
      description: 分页获取订阅频道下的文章，支持按账号或频道过滤。
      operationId: listArticles
      parameters:
        - name: page
          in: query
          description: 页码，从 1 开始
          required: false
          schema: { type: integer, default: 1, minimum: 1 }
        - name: page_size
          in: query
          description: 每页数量，范围 1–100
          required: false
          schema: { type: integer, default: 20, minimum: 1, maximum: 100 }
        - name: account_id
          in: query
          description: 按语鲸账号过滤（account_id 由 GET /accounts 获取）；留空聚合全部账号
          required: false
          schema: { type: string }
        - name: channel_id
          in: query
          description: 按频道过滤；留空返回全部频道
          required: false
          schema: { type: string }
        - name: include_outline
          in: query
          description: 传 true 时返回智能大纲字段 smart_outline
          required: false
          schema: { type: string, enum: ["true", "false"] }
        - name: published_after
          in: query
          description: 只返回发布时间 pub_time >= 该值的文章（Unix 秒，兼容 13 位毫秒）。常用于增量同步：传上次拉到的最大 pub_time。
          required: false
          schema: { type: integer }
        - name: published_before
          in: query
          description: 只返回发布时间 pub_time <= 该值的文章（Unix 秒，兼容 13 位毫秒）。与 published_after 组合成闭区间。
          required: false
          schema: { type: integer }
        - name: fields
          in: query
          description: 逗号分隔的字段白名单，只返回点名的字段以减小响应体积；不传返回全部。例：entry_id,title,description,pub_time。
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  message: { type: string, example: success }
                  data:
                    type: object
                    properties:
                      items:
                        type: array
                        items: { $ref: "#/components/schemas/Article" }
                      page: { type: integer, description: 当前页码 }
                      page_size: { type: integer, description: 每页数量 }
                      has_more: { type: boolean, description: 是否还有下一页（不返回总数，用它判断是否继续翻页） }

  /open-api/v1/articles/today:
    get:
      tags: [文章]
      summary: 获取今日文章
      description: 游标分页获取今日更新的文章，适合增量同步场景。
      operationId: listTodayArticles
      parameters:
        - name: limit
          in: query
          description: 单次返回条数
          required: false
          schema: { type: integer, default: 10 }
        - name: cursor
          in: query
          description: 翻页游标，来自上次响应的 cursor；首次请求留空
          required: false
          schema: { type: string }
        - name: channel_id
          in: query
          description: 按频道过滤；留空返回所有频道今日文章
          required: false
          schema: { type: string }
        - name: account_id
          in: query
          description: 按语鲸账号过滤（account_id 由 GET /accounts 获取）；留空聚合全部账号
          required: false
          schema: { type: string }
        - name: include_outline
          in: query
          description: 传 true 时返回智能大纲字段 smart_outline
          required: false
          schema: { type: string, enum: ["true", "false"] }
        - name: fields
          in: query
          description: 逗号分隔的字段白名单，只返回点名的字段以减小响应体积；不传返回全部。
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: object
                    properties:
                      items:
                        type: array
                        items: { $ref: "#/components/schemas/Article" }
                      cursor:
                        type: string
                        nullable: true
                        description: 下一页游标；为空表示已到末尾
                      has_more: { type: boolean, description: 是否还有更多数据 }

  /open-api/v1/articles/search:
    get:
      tags: [文章]
      summary: 搜索文章
      description: |
        按关键词搜索平台全库文章（供程序/Agent 按内容找文章），分词/语义混合检索、按相关度排序，
        与语鲸 App 搜索使用同一检索链路。不受频道追踪列表约束——搜索是「发现」能力。
        返回 entry_id、标题、摘要（abstract）、发布时间、封面、来源频道。
        典型用法：搜索定位候选 → 按标题和 abstract 筛选 → 再用 entry_id 调「获取文章详情」查看详情。
        该接口调用频率限制更严（默认每秒 1 次），请放慢节奏。
        query 不支持传链接（会被拒绝），添加新信源请用「订阅频道」。
      operationId: searchArticles
      parameters:
        - name: query
          in: query
          description: 搜索关键词
          required: true
          schema: { type: string }
        - name: page
          in: query
          description: 页码，从 1 开始
          required: false
          schema: { type: integer, default: 1 }
        - name: page_size
          in: query
          description: 每页数量，默认 20，最大 50
          required: false
          schema: { type: integer, default: 20 }
        - name: sort
          in: query
          description: 排序方式，relevance 相关度（默认）/ pub_time 发布时间倒序
          required: false
          schema: { type: string, enum: [relevance, pub_time], default: relevance }
        - name: account_id
          in: query
          description: 以哪个语鲸账号身份搜索（account_id 由 GET /accounts 获取）；留空用第一个绑定账号
          required: false
          schema: { type: string }
        - name: fields
          in: query
          description: 逗号分隔的字段白名单，只返回点名的字段以减小响应体积；不传返回全部。
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: object
                    properties:
                      items:
                        type: array
                        items: { $ref: "#/components/schemas/ArticleSearchItem" }
                      page: { type: integer }
                      page_size: { type: integer }
                      has_more: { type: boolean, description: 是否还有下一页 }
        "400":
          description: query 为空、传了链接，或搜索失败（业务码 40000，message 含具体原因）
        "429":
          description: 搜索过于频繁（业务码 42901），请退避重试

  /open-api/v1/articles/{entry_id}:
    get:
      tags: [文章]
      summary: 获取文章详情
      description: 根据 entry_id 获取单篇文章的完整内容。
      operationId: getArticleDetail
      parameters:
        - name: entry_id
          in: path
          description: 文章唯一 ID，从文章列表接口 items[].entry_id 获取
          required: true
          schema: { type: string }
        - name: fields
          in: query
          description: 逗号分隔的字段白名单，只返回点名的字段；不传返回全部。
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data: { $ref: "#/components/schemas/ArticleDetail" }
        "400":
          description: 文章不存在或获取失败（业务码 40400，message 含具体原因）

  /open-api/v1/channels:
    get:
      tags: [频道]
      summary: 获取订阅频道列表
      description: 获取当前用户所有绑定账号的订阅频道，可用于获取 channel_id 后传给文章接口过滤。
      operationId: listChannels
      parameters:
        - name: account_id
          in: query
          description: 按语鲸账号过滤（account_id 由 GET /accounts 获取）；留空返回所有账号的频道（去重）
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: array
                    items: { $ref: "#/components/schemas/Channel" }

  /open-api/v1/channels/manage:
    post:
      tags: [频道]
      summary: 管理追踪频道
      description: |
        一次调用同时增删：`track` 中的频道设为「追踪中」（会被 API 抓取，须为语鲸订阅中的频道，
        受额度上限约束，超限返回 403/40311），`freeze` 中的设为「已冻结」（不抓取、不占额度）。
        两字段可任填其一或都填，先冻结后追踪。
      operationId: manageChannels
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                track:
                  type: array
                  items: { type: string }
                  description: 设为追踪中的频道 ID（添加/恢复），单次最多 50 个
                freeze:
                  type: array
                  items: { type: string }
                  description: 设为冻结的频道 ID（停止抓取），单次最多 50 个
            example:
              track: ["CHANNEL_ID_1"]
              freeze: ["CHANNEL_ID_2"]
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  message: { type: string }
                  data:
                    type: object
                    properties:
                      quota:
                        type: object
                        properties:
                          max_channels: { type: integer, description: 可追踪频道上限 }
                          used: { type: integer, description: 当前追踪中的频道数 }
                      bindings:
                        type: array
                        items:
                          type: object
                          properties:
                            channel_id: { type: string }
                            channel_name: { type: string }
                            group_name: { type: string, description: 所在分组名称；未分组时不返回 }
                            status: { type: string, description: "active 追踪中 / frozen 已冻结" }
        "403":
          description: 超出可追踪频道额度上限（业务码 40311）

  /open-api/v1/channels/search:
    get:
      tags: [频道]
      summary: 搜索频道
      description: |
        按关键词搜索平台上的公开频道（供程序/Agent 自主发现频道），采用分词/语义检索、按相关度排序，
        与语鲸 App 搜索使用同一检索链路。返回 channel_id 后可用「订阅频道」订阅、或直接传给文章接口过滤。
        cursor 为翻页标记（请把上次响应的 next_cursor 原样回传，不要自行构造）。该接口调用频率限制更严（默认每秒 1 次），请放慢节奏。
      operationId: searchChannels
      parameters:
        - name: keyword
          in: query
          description: 搜索关键词，匹配频道名称与描述（忽略大小写）
          required: true
          schema: { type: string }
        - name: limit
          in: query
          description: 单页返回条数，默认 20，最大 50
          required: false
          schema: { type: integer, default: 20 }
        - name: cursor
          in: query
          description: 翻页游标，来自上次响应的 next_cursor；首次请求留空
          required: false
          schema: { type: string }
        - name: account_id
          in: query
          description: 以哪个语鲸账号身份搜索（account_id 由 GET /accounts 获取）；留空用第一个绑定账号
          required: false
          schema: { type: string }
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: object
                    properties:
                      channels:
                        type: array
                        items:
                          type: object
                          properties:
                            channel_id: { type: string, description: 频道唯一 ID，可传给「订阅频道」或文章接口 }
                            name: { type: string, description: 频道名称 }
                            description: { type: string, description: 频道描述 }
                      has_more: { type: boolean, description: 是否还有下一页 }
                      next_cursor: { type: string, description: 下一页游标；传给下次请求的 cursor，为空表示已到末尾 }
        "429":
          description: 搜索频率超限（业务码 42901），请放慢调用

  /open-api/v1/channels/subscribe:
    post:
      tags: [频道]
      summary: 订阅频道
      description: |
        订阅一个频道，并自动加入「追踪列表」（在额度内），订阅后即可用文章接口拉取其内容。
        channel_id 可通过「搜索频道」获取。若超出频道额度上限，仍会订阅成功但 tracked 返回 false，
        需在频道管理里腾出额度。
      operationId: subscribeChannel
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [channel_id]
              properties:
                channel_id: { type: string, description: 要订阅的频道 ID }
                account_id: { type: string, description: "用哪个语鲸账号订阅（account_id 由 GET /accounts 获取）；留空用第一个绑定账号" }
            example:
              channel_id: "CHANNEL_ID"
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  data:
                    type: object
                    properties:
                      channel_id: { type: string }
                      subscribed: { type: boolean, description: 是否订阅成功 }
                      tracked: { type: boolean, description: 是否已自动加入追踪列表；true 才能立即用文章接口拉取 }
                      track_message: { type: string, description: tracked 为 false 时的原因（多为超出频道额度上限） }

  /open-api/v1/channels/unsubscribe:
    post:
      tags: [频道]
      summary: 取消订阅频道
      description: 取消订阅一个频道，并同时从「追踪列表」移除、释放占用的额度。channel_id 可通过「获取订阅频道列表」获取。
      operationId: unsubscribeChannel
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [channel_id]
              properties:
                channel_id: { type: string, description: 要取消订阅的频道 ID }
                account_id: { type: string, description: "用哪个语鲸账号取消（account_id 由 GET /accounts 获取）；留空用第一个绑定账号" }
            example:
              channel_id: "CHANNEL_ID"
      responses:
        "200":
          description: 成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  code: { type: integer, example: 0 }
                  message: { type: string }

components:
  securitySchemes:
    AppID:
      type: apiKey
      in: header
      name: X-App-ID
    AppSecret:
      type: apiKey
      in: header
      name: X-App-Secret

  schemas:
    Article:
      type: object
      description: 文章列表项
      properties:
        entry_id: { type: string, description: 文章唯一 ID }
        title: { type: string, description: 文章标题 }
        orig_url: { type: string, description: 原文链接 }
        pub_time: { type: integer, description: 发布时间（Unix 时间戳） }
        description: { type: string, description: 语鲸生成的简短描述（一两句话 轻量字段 适合列表展示/索引） }
        abstract: { type: string, description: 语鲸生成的摘要（列表/搜索返回；详情接口不返回；为空时省略） }
        viewpoint:
          type: array
          items: { type: string }
          description: 语鲸生成的观点列表
        smart_outline: { type: string, description: 智能大纲（请求带 include_outline=true 时返回；为空时省略） }
        surface_url: { type: string, description: 文章封面图 URL }
        channel:
          type: object
          description: 来源频道（列表/搜索返回；详情接口不返回；为空时省略）
          properties:
            channel_id: { type: string }
            name: { type: string }
            description: { type: string }
            surface_url: { type: string }
        source_account:
          type: object
          description: 来源绑定账号（仅文章列表返回；为空时省略）
          properties:
            account_id: { type: string, description: 与 /accounts 返回的 account_id 一致 }
            nickname: { type: string, description: 来源账号昵称 }

    ArticleSearchItem:
      type: object
      description: 文章搜索结果项。含 abstract 便于筛选。
      properties:
        entry_id: { type: string, description: 文章唯一 ID，传给「获取文章详情」使用 }
        title: { type: string, description: 文章标题 }
        abstract: { type: string, description: 语鲸生成的事实性摘要，判断这篇是否相关的主要依据（同一事件的多篇快讯标题常高度雷同，靠它区分） }
        pub_time: { type: integer, description: 发布时间（Unix 时间戳） }
        surface_url: { type: string, description: 文章封面图 URL }
        channel:
          type: object
          description: 来源频道信息（channel_id / name / description / surface_url）

    ArticleDetail:
      type: object
      description: 文章详情
      properties:
        entry_id: { type: string, description: 文章唯一 ID }
        title: { type: string }
        orig_url: { type: string, description: 原文链接 }
        pub_time: { type: integer, description: 发布时间（Unix 时间戳） }
        description: { type: string, description: 语鲸生成的简短描述（一两句话 轻量字段 适合列表展示/索引） }
        viewpoint:
          type: array
          items: { type: string }
          description: 语鲸生成的观点列表
        smart_outline: { type: string, description: 智能大纲（纯文本，按层级缩进；可能为空/省略） }
        surface_url: { type: string, description: 文章封面图 URL }

    Channel:
      type: object
      description: 订阅频道
      properties:
        channel_id: { type: string, description: 频道唯一 ID，可用于文章接口的 channel_id 参数 }
        name: { type: string, description: 频道名称 }
        group_id: { type: string, description: 所在分组 ID；未分组时不返回 }
        group_name: { type: string, description: 所在分组名称；未分组时不返回 }
        description: { type: string, description: 频道描述 }
        surface_url: { type: string, description: 频道封面图 URL }
        create_time: { type: integer, description: 创建时间戳（可能省略） }

    Error:
      type: object
      description: |
        错误响应。只有 code 与 message，不包含 data；请以业务码为准。
        HTTP 状态码与业务码：
        400 参数有误（40000）或文章不存在/获取失败（40400，注意使用 HTTP 400 而不是 404）；
        401 App ID/Secret 错误或订阅失效（40110/40111/40112）；
        403 无权访问：套餐不支持 API（40113）、频道未在追踪列表（40310）、超出频道额度上限（40311）；
        429 请求频率超限：普通接口 42900、搜索接口 42901；500 服务端错误。
      properties:
        code: { type: integer, description: 业务错误码，非 0 }
        message: { type: string, description: 错误说明 }
