Gateway API 文档

OpenAI 兼容
POST/openai/v1/embeddings

Embeddings

创建文本嵌入向量。将文本转换为数值向量表示,可用于语义搜索、聚类等场景。

需要认证

请求参数

参数类型必填说明
modelstring必填嵌入模型 ID,如 "text-embedding-3-small"。
inputstring | string[]必填需要嵌入的文本或文本数组。
encoding_formatstring可选返回格式,可选 "float"(默认)或 "base64"。
dimensionsnumber可选输出向量的维度数。仅部分模型支持。

调用示例

typescript
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://llmapi.memene.cn/openai/v1",
  apiKey: "gw_memene_<keyId>_<secret>",
})

const res = await client.embeddings.create({
  "model": "text-embedding-3-small",
  "input": "The quick brown fox jumps over the lazy dog.",
  "encoding_format": "float"
})
console.log(res.data[0].embedding)

响应示例

json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        0.0023,
        -0.0094,
        0.0156,
        -0.0078,
        "..."
      ]
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 9,
    "total_tokens": 9
  }
}