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

# OpenAI 格式 - 嵌入

> - 适用于所有兼容 OpenAI 格式嵌入模型的通用 Embeddings API 参考
- 将文本转换为向量表示
- 支持单条或批量输入
- 可配置输出维度和编码格式




## OpenAPI

````yaml openapi/zh/openai-format-embeddings.json POST /v1/embeddings
openapi: 3.1.0
info:
  title: OpenAI Format - Embeddings
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1/embeddings:
    post:
      tags:
        - Text Series > OpenAI Format
      summary: OpenAI Format - Embeddings
      description: |
        - 适用于所有兼容 OpenAI 格式嵌入模型的通用 Embeddings API 参考
        - 将文本转换为向量表示
        - 支持单条或批量输入
        - 可配置输出维度和编码格式
      operationId: openai-format-embeddings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmbeddingRequest'
            examples:
              single-text:
                summary: 单文本嵌入
                description: 将单条文本转换为向量
                value:
                  model: text-embedding-3-small
                  input: 机器学习是人工智能的一个分支
              batch-texts:
                summary: 批量文本嵌入
                description: 将多条文本批量转换为向量，适用于构建知识库索引
                value:
                  model: text-embedding-3-small
                  input:
                    - 如何重置密码？
                    - 订单退款需要多长时间？
                    - 如何联系客服？
                    - 配送时间是多久？
              custom-dimensions:
                summary: 自定义维度
                description: 指定输出向量维度，减小存储空间
                value:
                  model: text-embedding-3-small
                  input: 深度学习模型的训练过程包括前向传播和反向传播两个阶段
                  dimensions: 256
      responses:
        '200':
          $ref: '#/components/responses/EmbeddingSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    EmbeddingRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
          description: 嵌入模型名称
          example: text-embedding-3-small
        input:
          description: 要嵌入的文本或文本列表
          oneOf:
            - type: string
              description: 单条文本
            - type: array
              description: 文本列表
              items:
                type: string
        encoding_format:
          type: string
          description: 输出编码格式
          enum:
            - float
            - base64
          default: float
        dimensions:
          type: integer
          description: 输出向量维度
    EmbeddingResponse:
      type: object
      properties:
        object:
          type: string
          description: 对象类型
          enum:
            - list
        data:
          type: array
          description: 嵌入向量列表
          items:
            type: object
            properties:
              object:
                type: string
                description: 对象类型
                enum:
                  - embedding
              index:
                type: integer
                description: 嵌入索引
                example: 0
              embedding:
                type: array
                description: 嵌入向量
                items:
                  type: number
                example:
                  - 0.0023064255
                  - -0.009327292
                  - 0.015797347
        model:
          type: string
          description: 使用的模型
        usage:
          type: object
          description: 用量统计
          properties:
            prompt_tokens:
              type: integer
              description: 提示token数
              example: 8
            total_tokens:
              type: integer
              description: 总token数
              example: 8
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求参数无效
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: API密钥无效
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 访问被拒绝
            type:
              type: string
              example: permission_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 请求频率超限
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 服务器内部错误
            type:
              type: string
              example: server_error
  responses:
    EmbeddingSuccess:
      description: 嵌入向量响应
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EmbeddingResponse'
    BadRequest:
      description: 请求错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: 余额不足
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: 禁止访问
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: 请求过多
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## 所有接口均需要使用Bearer Token进行认证 ##

        使用时在请求头中添加：

        `Authorization: Bearer YOUR_API_KEY`

````