curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The way of the samurai"
}'
curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"The way of the samurai",
"Machine learning is transforming the world",
"Tokyo is the capital of Japan"
]
}'
import numpy as np
from openai import OpenAI
client = OpenAI(
api_key="sk-samurai-YOUR_KEY",
base_url="https://www.samuraiapi.in/v1"
)
def embed(texts):
res = client.embeddings.create(model="text-embedding-3-small", input=texts)
return [d.embedding for d in res.data]
def cosine_sim(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
docs = ["Tokyo is the capital of Japan", "Paris is the capital of France"]
doc_vecs = embed(docs)
query_vec = embed(["What is the capital of Japan?"])[0]
scores = [cosine_sim(query_vec, v) for v in doc_vecs]
print(docs[np.argmax(scores)])
# => "Tokyo is the capital of Japan"
{
"object": "list",
"data": [
{
"index": 0,
"object": "embedding",
"embedding": [0.0023064255, -0.009327292, 0.015797656, "...1536 total floats..."]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
Embeddings
Create Embedding
Convert text to vector representations for semantic search, RAG, clustering, and classification.
POST
/
embeddings
curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The way of the samurai"
}'
curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"The way of the samurai",
"Machine learning is transforming the world",
"Tokyo is the capital of Japan"
]
}'
import numpy as np
from openai import OpenAI
client = OpenAI(
api_key="sk-samurai-YOUR_KEY",
base_url="https://www.samuraiapi.in/v1"
)
def embed(texts):
res = client.embeddings.create(model="text-embedding-3-small", input=texts)
return [d.embedding for d in res.data]
def cosine_sim(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
docs = ["Tokyo is the capital of Japan", "Paris is the capital of France"]
doc_vecs = embed(docs)
query_vec = embed(["What is the capital of Japan?"])[0]
scores = [cosine_sim(query_vec, v) for v in doc_vecs]
print(docs[np.argmax(scores)])
# => "Tokyo is the capital of Japan"
{
"object": "list",
"data": [
{
"index": 0,
"object": "embedding",
"embedding": [0.0023064255, -0.009327292, 0.015797656, "...1536 total floats..."]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
string
required
Embedding model. Options:
text-embedding-3-small (1536 dims, fast), text-embedding-3-large (3072 dims, best accuracy), text-embedding-ada-002 (legacy).string | array
required
Text to embed. Pass a single string or an array of strings for batch embedding.
string
default:"float"
float returns an array of numbers. base64 returns a base64-encoded string (smaller payload).integer
Number of output dimensions (model-dependent). Only for
text-embedding-3-* models.curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": "The way of the samurai"
}'
curl https://www.samuraiapi.in/v1/embeddings \
-H "Authorization: Bearer $SAMURAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-3-small",
"input": [
"The way of the samurai",
"Machine learning is transforming the world",
"Tokyo is the capital of Japan"
]
}'
import numpy as np
from openai import OpenAI
client = OpenAI(
api_key="sk-samurai-YOUR_KEY",
base_url="https://www.samuraiapi.in/v1"
)
def embed(texts):
res = client.embeddings.create(model="text-embedding-3-small", input=texts)
return [d.embedding for d in res.data]
def cosine_sim(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
docs = ["Tokyo is the capital of Japan", "Paris is the capital of France"]
doc_vecs = embed(docs)
query_vec = embed(["What is the capital of Japan?"])[0]
scores = [cosine_sim(query_vec, v) for v in doc_vecs]
print(docs[np.argmax(scores)])
# => "Tokyo is the capital of Japan"
{
"object": "list",
"data": [
{
"index": 0,
"object": "embedding",
"embedding": [0.0023064255, -0.009327292, 0.015797656, "...1536 total floats..."]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
⌘I