API reference
Embeddings and moderation
This article covers two endpoints. Embeddings converts text into semantic vectors for semantic search and RAG applications. Moderations detects policy-violating content in text for content safety.
Embeddings
Embeddings maps text to numeric vectors. Distances between vectors reflect semantic similarity, enabling text retrieval and matching by meaning.
Supported models
- Capability note: The platform provides /v1/embeddings. See the Model Catalog (Models in the console) for available embedding models.
Endpoint and parameters
POST https://api.yomiapi.com/v1/embeddings
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (use an available embedding model from the Model Catalog) |
input | string / array | Yes | Text to embed; arrays support batch input |
dimensions | integer | No | Output vector dimensions; supported by some models only |
encoding_format | string | No | float or base64 |
Code examples
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.yomiapi.com/v1"
)
# Single text
response = client.embeddings.create(
model="YOUR_AVAILABLE_EMBEDDING_MODEL_ID",
input="The food at this restaurant is excellent and the service is attentive"
)
print(len(response.data[0].embedding))
# Batch text
batch = client.embeddings.create(
model="YOUR_AVAILABLE_EMBEDDING_MODEL_ID",
input=["Semantic search", "Vector database", "Retrieval-augmented generation"]
)
print(len(batch.data))
Applications
- Semantic search: Match documents by meaning rather than keywords.
- RAG systems: Retrieve knowledge-base content to improve model answers and reduce hallucinations.
- Clustering and classification: Group or label text data.
- Recommendation systems: Recommend similar content based on previous behavior.
Do not mix vectors from different models. The retrieval collection and queries must use the same embedding model. Switching models requires re-embedding all existing text.
Moderations
Moderations checks text for content such as violence, sexual content, hate speech, harassment and self-harm. It is compatible with the OpenAI Moderation format. Results include an overall decision and confidence scores for each category, so you can choose thresholds for your application.
Endpoint address
POST https://api.yomiapi.com/v1/moderations
Code examples
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.yomiapi.com/v1"
)
response = client.moderations.create(
input="Text to check"
)
result = response.results[0]
print("Flagged:", result.flagged)
if result.flagged:
print("Categories:", result.categories)
print("Confidence:", result.category_scores)
Response fields
flagged(boolean): Whether the content is flagged.categories(object): A true/false decision for each category.category_scores(object): Confidence scores for each category, from 0.0 to 1.0.
Applications
- UGC filtering: Automatically filter comments, posts and other user-generated content.
- AI output monitoring: Ensure generated content follows safety requirements.
- Realtime chat moderation: Check chat rooms and support conversations in real time.
Recommendations
- Prefer batches: Embeddings accepts arrays. Batch processing is more efficient than separate requests.
- Tune thresholds: Set custom moderation thresholds based on
category_scoresrather than relying only onflagged, balancing false positives against missed detections.
