- 起步
- 介绍
- 导言
- 身份验证
- 发出请求
- 参数详情
- 音频(Audio)
- 聊天(Chat)
- 自动补全(Completions)
- 嵌入(Embeddings)
- 微调(Fine-tuning)
- 图像(Images)
- 模型(Models)
- 文件(Files)
- 审查(Moderations)
- 助手测试版(AssistantsBeta)
- 线程数(Threads)
- 留言(Messages)
- 运行(Runs)
- 已弃用-音频(Audio)
- English
- Authentication
- Making requests
- Streaming
- Debugging requests
- Backward compatibility
- Administration
- Introduction
- Batch
- Models
- Invites
- Chat
- Users
- Projects
- Project users
- Project service accounts
- Project API keys
- Audit logs
- Usage
- Project rate limits
- Completions
- Uploads
- Images
- Embeddings
- Audio
- Files
- Fine-tuning
- Moderations
- Assistants (v1)
- Threads (v1)
- Messages (v1)
- Runs (v1)
Create embeddings
POST
https://api.openai.com/v1/embeddings
Request
Authorization
Provide your bearer token in the
Authorization
header when making requests to protected resources.Example:
Authorization: Bearer ********************
Header Params
Authorization
string
required
Example:
Bearer $OPENAI_API_KEY
Content-Type
string
required
Example:
application/json
Body Params application/json
input
string
required
text-embedding-ada-002
), cannot be an empty string, and any array must be 2048 dimensions or less. Example Python code for counting tokens.model
string
required
encoding_format
string
required
float
or base64
.Example
{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002",
"encoding_format": "float"
}
Request samples
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.openai.com/v1/embeddings' \
--header 'Authorization: Bearer $OPENAI_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": "The food was delicious and the waiter...",
"model": "text-embedding-ada-002",
"encoding_format": "float"
}'
Responses
🟢200Success
application/json
Body
object
string
required
data
array [object {3}]
required
object
string
optional
embedding
array[number]
optional
index
integer
optional
model
string
required
usage
object
required
prompt_tokens
integer
required
total_tokens
integer
required
Example
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
.... (1536 floats total for ada-002)
-0.0028842222,
],
"index": 0
}
],
"model": "text-embedding-ada-002",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
Modified at 2024-12-13 10:20:37