本页内容
嵌入
基础路径:/v1
POST /embeddings
为文本、Token ID 或聊天消息创建嵌入。请只发送 input 或 messages 中的一个。每次请求最多允许 20 个输入或对话。messages 中的图像必须是 base64 数据 URI,图像总负载不得超过 20MB。
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
| Core Input | |||
| model | string | required | Embedding model identifier. Use GET /v1/embedding-models to list models available to your account. |
| input | string | list[string] | list[int] | list[list[int]] | list[chat messages] | required (or messages) | Text, token IDs, a list of texts, or chat messages to embed. Exactly one of input or messages must be provided. Lists are capped at 20 items per request. |
| messages | list[message] | list[list[message]] | required (or input) | One chat conversation or a batch of conversations to embed. Exactly one of input or messages must be provided. Batches are capped at 20 conversations. Use content parts for multimodal input; image URLs must be base64 data URIs (data:image/...) and the total image payload is limited to 20MB. |
| Encoding | |||
| encoding_format | "float" | "base64" | optional | Embedding encoding. "float" returns a JSON number array; "base64" returns base64-encoded binary and is more compact. Default: "float". |
| dimensions | integer | optional | Requested embedding size. Must be a positive integer when set. Model support and truncation behavior are model-dependent. |
| embed_dtype | "float32" | "float16" | "bfloat16" | "fp8_e4m3" | "fp8_e5m2" | optional | Numeric dtype used when encoding_format is "base64". Default: "float32". |
| endianness | "native" | "big" | "little" | optional | Byte order used when encoding_format is "base64". Default: "native". |
| use_activation | boolean | null | optional | Whether to apply the pooler's activation to the output. null uses the model's default, which is usually true. |
| Truncation & Tokenization | |||
| truncate_prompt_tokens | integer | optional | Truncate each input to this many tokens. Use -1 to keep all tokens, or a positive integer to keep only that many. |
| truncation_side | "left" | "right" | optional | Side to keep when truncating. "right" keeps the first N tokens; "left" keeps the last N tokens. |
| padding | "max_length" | "do_not_pad" | optional | Tokenizer padding mode. "max_length" is required by some fixed-length embedding models such as SigLIP to produce comparable embeddings. |
| add_special_tokens | boolean | optional | Whether to add model special tokens (for example BOS) to the input. Defaults to true for text input and false for chat messages. |
1curl -X POST https://api.arliai.com/v1/embeddings \
2-H "Content-Type: application/json" \
3-H "Authorization: Bearer your_api_key" \
4-d '{
5 "model": "EMBEDDING_MODEL_NAME",
6 "input": [
7 "The food was delicious.",
8 "The service was slow."
9 ],
10 "encoding_format": "float"
11}'响应示例
1{
2 "id": "embd-2c0a5f6e-4f1b-4a5e-9f2f-3c7f9d1a6b8e",
3 "object": "list",
4 "created": 1760000000,
5 "model": "EMBEDDING_MODEL_NAME",
6 "data": [
7 {
8 "index": 0,
9 "object": "embedding",
10 "embedding": [0.0123, -0.0456, 0.0789]
11 },
12 {
13 "index": 1,
14 "object": "embedding",
15 "embedding": [-0.0321, 0.0678, 0.0912]
16 }
17 ],
18 "usage": {
19 "prompt_tokens": 12,
20 "total_tokens": 12
21 }
22}The embedding array above is shortened for display. For compact responses, use encoding_format: "base64". Binary responses use embed_dtype and endianness to describe how to decode them.
1curl -X POST https://api.arliai.com/v1/embeddings \
2-H "Content-Type: application/json" \
3-H "Authorization: Bearer your_api_key" \
4-d '{
5 "model": "EMBEDDING_MODEL_NAME",
6 "input": ["A compact base64 embedding"],
7 "encoding_format": "base64",
8 "embed_dtype": "float32",
9 "endianness": "native"
10}'POST /embeddings(多模态)
将 messages 与内容部分结合使用,可同时嵌入图像和文本。每个 image_url.url 必须是 base64 数据 URI,例如 data:image/jpeg;base64,...;远程图像 URL 会被拒绝。
1curl -X POST https://api.arliai.com/v1/embeddings \
2-H "Content-Type: application/json" \
3-H "Authorization: Bearer your_api_key" \
4-d '{
5 "model": "EMBEDDING_MODEL_NAME",
6 "messages": [
7 {
8 "role": "user",
9 "content": [
10 {"type": "text", "text": "A red bicycle leaning against a wall."},
11 {
12 "type": "image_url",
13 "image_url": {
14 "url": "data:image/jpeg;base64,your_base64_encoded_image"
15 }
16 }
17 ]
18 }
19 ],
20 "encoding_format": "float"
21}'POST /embeddings(批量对话)
将对话数组传递给 messages,即可在单次请求中嵌入最多 20 个对话。每个对话必须是非空的消息数组。
1curl -X POST https://api.arliai.com/v1/embeddings \
2-H "Content-Type: application/json" \
3-H "Authorization: Bearer your_api_key" \
4-d '{
5 "model": "EMBEDDING_MODEL_NAME",
6 "messages": [
7 [
8 {"role": "user", "content": "First conversation to embed."}
9 ],
10 [
11 {"role": "user", "content": "Second conversation to embed."}
12 ]
13 ]
14}'