Embedding (Embedding-3)
Text embedding interface for semantic search and text similarity computation.
API Endpoints
POST
/embeddingsText embedding
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | Model name: Embedding-3 |
input | string | array | Required | Text or array of texts to embed |
Request Example
Request Example
{
"model": "Embedding-3",
"input": "智谱AI是一家专注于大模型的公司"
}Response Example
Response Example
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [0.123, -0.456, 0.789, ...],
"index": 0
}
],
"model": "Embedding-3",
"usage": {
"prompt_tokens": 10,
"total_tokens": 10
}
}Code Examples
Python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-proxy-domain.com/v1"
)
response = client.embeddings.create(
model="Embedding-3",
input="智谱AI是一家专注于大模型的公司"
)
embedding_vector = response.data[0].embedding
print(f"向量维度: {len(embedding_vector)}")JavaScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://your-proxy-domain.com/v1'
});
async function getEmbedding() {
const response = await client.embeddings.create({
model: 'Embedding-3',
input: '智谱AI是一家专注于大模型的公司'
});
const embedding = response.data[0].embedding;
console.log(`向量维度: ${embedding.length}`);
}
getEmbedding();cURL
curl https://your-proxy-domain.com/v1/embeddings \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "Embedding-3",
"input": "智谱AI是一家专注于大模型的公司"
}'