> ## 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.

# Create Embedding

<Note>
  Note: For setting the embedding model name, refer to the [System Supported Embedding Models List](https://geekai.dev/models). The request/response parameter structure is fully compatible with [OpenAI](https://platform.openai.com/docs/api-reference/embeddings). When switching models, you only need to modify the corresponding model name. If the model request/response parameters are inconsistent with OpenAI, GeekAI will automatically convert and align them at the underlying level.
  The response data format is fully compatible with OpenAI.
</Note>

### cURL Request Example

```bash theme={null}
curl --location 'https://geekai.dev/api/v1/embeddings' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {YOUR_GEEKAI_API_KEY}' \
--data '{
    "input": [
        "The food was delicious and the waiter..."
    ],
    "model": "text-embedding-3-small"
}'
```


## OpenAPI

````yaml openapi.yaml POST /embeddings
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:
  /embeddings:
    post:
      tags:
        - Embeddings
      summary: 文本/图片嵌入向量生成接口
      description: 将文本/图片转换为向量表示的接口
      operationId: createEmbeddings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              properties:
                model:
                  type: string
                  description: 嵌入模型
                  example: text-embedding-3-small
                input:
                  oneOf:
                    - type: string
                      description: 单条文本
                    - type: array
                      description: 文本数组
                      items:
                        type: string
                    - type: array
                      description: 图文数组
                      items:
                        oneOf:
                          - $ref: '#/components/schemas/TextContentPart'
                          - $ref: '#/components/schemas/ImageContentPart'
                          - $ref: '#/components/schemas/VideoContentPart'
                  description: 文本字符串或者图文对象列表，单行文本字符数受模型上下文长度限制
                  example:
                    - 你好
                intent:
                  type: string
                  description: 嵌入意图，用于指定嵌入的使用场景，目前仅 Cohere 向量模型支持该字段，当对图片进行向量化需要指定为 image
                  enum:
                    - search_document
                    - search_query
                    - classification
                    - clustering
                    - image
                dimensions:
                  type: integer
                  description: 输出向量维度
                  default: 1536
                  example: 1536
                retries:
                  type: integer
                  description: 自动重试次数，默认0，表示失败不重试
                  default: 0
                  example: 0
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                required:
                  - model
                  - data
                  - usage
                properties:
                  model:
                    type: string
                    description: 使用的嵌入模型
                    example: text-embedding-3-small
                  data:
                    type: array
                    description: 嵌入向量数据列表
                    items:
                      type: object
                      required:
                        - embedding
                        - index
                      properties:
                        embedding:
                          type: array
                          items:
                            type: number
                            format: float
                          description: 向量数据
                          example:
                            - -0.006929
                            - 0.0023415
                            - ...
                        index:
                          type: integer
                          description: 在输入数组中的索引位置
                          minimum: 0
                          example: 0
                  usage:
                    type: object
                    required:
                      - prompt_tokens
                      - total_tokens
                    properties:
                      prompt_tokens:
                        type: integer
                        description: 输入文本的token数量
                        example: 8
                      total_tokens:
                        type: integer
                        description: 总token数量
                        example: 8
                      prompt_tokens_details:
                        type: object
                        description: 输入文本消耗明细
                        properties:
                          text_tokens:
                            type: integer
                            description: 文本token数
                          image_tokens:
                            type: integer
                            description: 图片token数
                  object:
                    type: string
                    description: 响应对象类型
                    enum:
                      - list
                    default: list
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          description: 输入文本超出长度限制
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/StandardError'
components:
  schemas:
    TextContentPart:
      type: object
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
          description: 内容类型
        text:
          type: string
          description: 文本内容
    ImageContentPart:
      type: object
      required:
        - type
        - image_url
      properties:
        type:
          type: string
          enum:
            - image_url
          description: 内容类型
        image_url:
          type: object
          required:
            - url
          properties:
            url:
              type: string
              description: 图片URL或Base64编码的图片数据
          description: 图片URL对象
    VideoContentPart:
      type: object
      required:
        - type
        - video_url
      properties:
        type:
          type: string
          enum:
            - video_url
          description: 内容类型
        video_url:
          type: object
          required:
            - url
          properties:
            url:
              type: string
              description: 视频URL
          description: 视频URL对象
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: 错误代码
          example: invalid_request
        message:
          type: string
          description: 错误信息描述
          example: 请求参数不合法
  responses:
    ValidationError:
      description: 参数验证错误
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                example: validation_error
              message:
                type: string
                example: 参数验证失败
              details:
                type: object
                additionalProperties:
                  type: string
                example:
                  field: 错误描述
    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密钥认证

````