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

# 上传文件

极客智坊提供了文件上传与内容提取功能，支持多种文件格式，包括.PDF .DOCX .DOC .XLS .XLSX .PPT .PPTX .PNG .JPG .JPEG .CSV .PY .TXT .MD .BMP .GIF等，你可以通过上传文件接口上传待识别文件，然后通过文件内容提取接口获取文件内容，借助该基础服务，你可以完成AI文件对话/RAG等上层业务场景的功能实现。

### cURL 请求示例

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/files' \
--header 'Authorization: Bearer {$GEEKAI_API_KEY}' \
--form 'file=@"/E:/文档/geekai/test.pdf"'
--form 'purpose="file-extract"'
```

### Postman 请求响应示例

<img src="https://static.geekai.co/storage/2024/12/12/image-20241212192731879.png" className="mt-2" alt="上传文件" />


## OpenAPI

````yaml openapi.yaml POST /files
openapi: 3.1.0
info:
  title: 极客智坊 API文档
  description: 极客智坊 API 消息接口规范文档
  version: 1.0.0
servers:
  - url: https://geekai.co/api/v1
    description: 国内代理入口
  - url: https://geekai.dev/api/v1
    description: 海外代理入口
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /files:
    post:
      tags:
        - Files
      summary: 文件上传接口
      description: 上传并处理各种格式的文件，支持获取文件URL、内容提取等功能。
      operationId: uploadFile
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: >-
                    上传的文件，目前支持PDF/DOCX/XLSX/PPTX/PNG/JPG/JPEG/CSV/TXT/MD/MP3/MP4等格式
                  example: '@/E:/文档/test.pdf'
                purpose:
                  type: string
                  description: 上传目的,目前仅支持获取文件URL、文件内容提取
                  default: file-url
                  enum:
                    - file-url
                    - file-extract
                format:
                  type: string
                  description: 返回文件内容格式，目前仅支持文本格式
                  default: text
                  example: text
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                required:
                  - uuid
                  - status
                properties:
                  uuid:
                    type: string
                    format: uuid
                    description: 文件唯一ID,可通过该ID获取文件内容
                  name:
                    type: string
                    description: 文件名称
                  size:
                    type: integer
                    description: 文件大小
                  type:
                    type: string
                    description: 文件MIME类型
                  status:
                    type: string
                    description: '文件状态: pending（待处理）/reading（读取中）/failed（读取失败）/done（已读取）'
                    enum:
                      - pending
                      - reading
                      - processing
                      - failed
                      - done
                  md5:
                    type: string
                    description: 文件MD5值
                  url:
                    type: string
                    description: 文件URL地址
                  content:
                    type: string
                    description: 文件内容（只有status=done时，才会填充该字段）
        '400':
          description: 请求参数错误
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - example:
                      code: invalid_file
                      message: 不支持的文件格式
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          description: 文件大小超出限制
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - example:
                      code: file_too_large
                      message: 文件大小超过50MB限制
        '415':
          description: 不支持的文件类型
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Error'
                  - example:
                      code: unsupported_media_type
                      message: 不支持的文件类型
        '500':
          $ref: '#/components/responses/StandardError'
components:
  schemas:
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: 错误代码
          example: invalid_request
        message:
          type: string
          description: 错误信息描述
          example: 请求参数不合法
  responses:
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: unauthorized
              message:
                type: string
                example: Invalid API key or token
    StandardError:
      description: 标准错误响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: API认证token
    apiKeyAuth:
      type: apiKey
      in: header
      name: GeekAI-API-Key
      description: API密钥认证

````