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

# 文本嵌入

> 使用 [GLM Embedding](/cn/guide/models/embedding/embedding-3) 系列模型将文本转换为高维向量表示，用于语义相似性和搜索。点击 **Try it** 按钮可快速试用。



## OpenAPI

````yaml /openapi/openapi.json post /paas/v4/embeddings
openapi: 3.0.1
info:
  title: ZHIPU AI API
  description: ZHIPU AI 接口提供强大的 AI 能力，包括聊天对话、工具调用和视频生成。
  license:
    name: ZHIPU AI 开发者协议和政策
    url: https://chat.z.ai/legal-agreement/terms-of-service
  version: 1.0.0
  contact:
    name: Z.AI 开发者
    url: https://chat.z.ai/legal-agreement/privacy-policy
    email: user_feedback@z.ai
servers:
  - url: https://open.bigmodel.cn/api/
    description: 开放平台服务
security:
  - bearerAuth: []
tags:
  - name: 模型 API
    description: Chat API
  - name: 工具 API
    description: Web Search API
  - name: Agent API
    description: Agent API
  - name: 文件 API
    description: File API
  - name: 知识库 API
    description: Knowledge API
  - name: 实时 API
    description: Realtime API
  - name: 批处理 API
    description: Batch API
  - name: 助理 API
    description: Assistant API
  - name: 智能体 API（旧）
    description: QingLiu Agent API
paths:
  /paas/v4/embeddings:
    post:
      tags:
        - 模型 API
      summary: 文本嵌入
      description: >-
        使用 [GLM Embedding](/cn/guide/models/embedding/embedding-3)
        系列模型将文本转换为高维向量表示，用于语义相似性和搜索。点击 **Try it** 按钮可快速试用。
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmbeddingCreateRequest'
            examples:
              文本嵌入示例:
                value:
                  model: embedding-3
                  input: 你好，今天天气怎么样.
                  dimensions: 2
        required: true
      responses:
        '200':
          description: 业务处理成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EmbeddingResponse'
        default:
          description: 请求失败。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    EmbeddingCreateRequest:
      type: object
      required:
        - model
        - input
      properties:
        model:
          type: string
          description: 嵌入模型名称，如 `embedding-3、embedding-2`
          enum:
            - embedding-3
            - embedding-2
        input:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: |-
            输入文本，支持字符串或字符串数组。
            - `embedding-2` 的单条请求最多支持 `512` 个`Tokens`，数组总长度不得超过`8K` 
            - `embedding-3` 的单条请求最多支持 `3072` 个`Tokens`，且数组最大不得超过 `64` 条
        dimensions:
          type: integer
          minimum: 1
          description: >-
            输出向量维度，`Embedding-3` 默认 `2048`，`Embedding-2` 固定 `1024`。`Embedding-3`
            支持自定义，可选值：`256、512、1024`或`2048`。
          enum:
            - 2048
            - 1024
            - 512
            - 256
    EmbeddingResponse:
      type: object
      description: 文本嵌入响应对象，包含嵌入向量结果、模型信息和 `tokens` 统计。
      properties:
        model:
          type: string
          description: 模型编码。
        object:
          type: string
          enum:
            - list
          description: 结果类型，目前为 `list`。
        data:
          type: array
          description: 模型生成的数组结果。每个元素为单条文本的嵌入结果对象。
          items:
            $ref: '#/components/schemas/EmbeddingObject'
        usage:
          $ref: '#/components/schemas/EmbeddingUsage'
          description: 本次模型调用的 `tokens` 数量统计。
    Error:
      type: object
      properties:
        error:
          required:
            - code
            - message
          type: object
          properties:
            code:
              type: string
            message:
              type: string
    EmbeddingObject:
      type: object
      description: 单条文本的嵌入向量对象。
      properties:
        index:
          type: integer
          description: 结果下标。该嵌入向量对应的输入文本在输入数组中的索引。
        object:
          type: string
          enum:
            - embedding
          description: 结果类型，目前为 `embedding`。
        embedding:
          type: array
          items:
            type: number
          description: '`embedding` 的处理结果，返回向量化表征的数组。'
    EmbeddingUsage:
      type: object
      description: 本次模型调用的 `tokens` 数量统计。
      properties:
        prompt_tokens:
          type: integer
          description: 用户输入的 `tokens` 数量。
        completion_tokens:
          type: integer
          description: 模型输出的 `tokens` 数量。
        total_tokens:
          type: integer
          description: 总 `tokens` 数量。
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        标准的 HTTP Bearer 认证方式，在 [API
        Keys](https://bigmodel.cn/usercenter/proj-mgmt/apikeys) 页面获取密钥。

````