Stored Completions
Retrieve, update, and manage stored chat completion records. Every inference request is automatically stored and can be queried through these CRUD endpoints.
Overview
When you send a chat completion request through the inference API, Xerotier automatically stores the complete request and response. The Stored Completions API lets you:
- List -- Browse stored completions with filtering by model, metadata, and pagination.
- Retrieve -- Get the full details of a specific completion including usage and parameters.
- Update -- Attach or modify metadata on stored completions for tagging and organization.
- Delete -- Remove stored completions you no longer need.
- Messages -- Retrieve the full message history (input and output) for a completion.
All endpoints require API key authentication and are scoped to the authenticated project. Completions are stored using the platform's standard two-tier storage architecture. For details on storage tiers, encryption, retention, and billing, see Storage.
List Completions
GET /v1/chat/completions
Returns a paginated list of stored completions for the project.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| afteroptional | string | Cursor for pagination. Pass the id of the last item from the previous page. |
| limitoptional | integer | Maximum number of completions to return (1-100, default 20). |
| orderoptional | string | Sort order: "asc" or "desc" (default "desc"). |
| modeloptional | string | Filter by model name. |
| metadata[key]optional | string | Filter by metadata key-value pair. Example: metadata[env]=production. |
curl "https://api.xerotier.ai/proj_ABC123/my-endpoint/v1/chat/completions?limit=5&order=desc&model=llama3-8b" \
-H "Authorization: Bearer xero_myproject_your_api_key"
Response
{
"object": "list",
"data": [
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "llama3-8b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 9,
"total_tokens": 21
},
"metadata": {"env": "production"},
"service_tier": "default",
"system_fingerprint": "fp_abc123"
}
],
"has_more": true
}
Get Completion
GET /v1/chat/completions/{id}
Retrieves a single stored completion by its ID, including full usage details and request parameters.
curl https://api.xerotier.ai/proj_ABC123/my-endpoint/v1/chat/completions/chatcmpl-abc123 \
-H "Authorization: Bearer xero_myproject_your_api_key"
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "llama3-8b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 9,
"total_tokens": 21,
"prompt_tokens_details": null,
"completion_tokens_details": null
},
"metadata": {},
"service_tier": "default",
"system_fingerprint": "fp_abc123",
"request_id": "req_xyz789",
"temperature": 0.7,
"top_p": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0
}
Update Completion
POST /v1/chat/completions/{id}
Updates the metadata on a stored completion. Use this to tag or annotate completions for later filtering.
Request Body
| Parameter | Type | Description |
|---|---|---|
| metadatarequired | object | Key-value pairs to set on the completion. Replaces existing metadata. |
curl -X POST https://api.xerotier.ai/proj_ABC123/my-endpoint/v1/chat/completions/chatcmpl-abc123 \
-H "Authorization: Bearer xero_myproject_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"metadata": {
"env": "production",
"team": "nlp",
"reviewed": "true"
}
}'
Response
Returns the updated completion object (same format as Get Completion).
Delete Completion
DELETE /v1/chat/completions/{id}
Permanently deletes a stored completion and its associated messages.
curl -X DELETE https://api.xerotier.ai/proj_ABC123/my-endpoint/v1/chat/completions/chatcmpl-abc123 \
-H "Authorization: Bearer xero_myproject_your_api_key"
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"deleted": true
}
Get Messages
GET /v1/chat/completions/{id}/messages
Retrieves the full message history for a stored completion, including both the input messages (system, user, tool) and the assistant response.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| afteroptional | string | Cursor for pagination. |
| limitoptional | integer | Maximum messages to return (default 20). |
| orderoptional | string | Sort order: "asc" (default) or "desc". |
curl "https://api.xerotier.ai/proj_ABC123/my-endpoint/v1/chat/completions/chatcmpl-abc123/messages?order=asc" \
-H "Authorization: Bearer xero_myproject_your_api_key"
Response
{
"object": "list",
"data": [
{
"id": "msg_001",
"role": "system",
"content": "You are a helpful assistant."
},
{
"id": "msg_002",
"role": "user",
"content": "Hello!"
},
{
"id": "msg_003",
"role": "assistant",
"content": "Hello! How can I help you today?"
}
],
"has_more": false
}
Client Examples
Python (requests)
import requests
headers = {
"Authorization": "Bearer xero_myproject_your_api_key",
"Content-Type": "application/json"
}
base = "https://api.xerotier.ai/proj_ABC123/my-endpoint/v1"
# List stored completions
completions = requests.get(
f"{base}/chat/completions?limit=5&order=desc",
headers=headers
).json()
for c in completions["data"]:
print(f"{c['id']} - {c['model']} ({c['usage']['total_tokens']} tokens)")
# Get a specific completion
comp = requests.get(
f"{base}/chat/completions/chatcmpl-abc123",
headers=headers
).json()
print(f"Model: {comp['model']}, Finish: {comp['choices'][0]['finish_reason']}")
# Update completion metadata
requests.post(
f"{base}/chat/completions/chatcmpl-abc123",
headers=headers,
json={
"metadata": {
"env": "production",
"reviewed": "true"
}
}
)
# Get completion messages
messages = requests.get(
f"{base}/chat/completions/chatcmpl-abc123/messages?order=asc",
headers=headers
).json()
for msg in messages["data"]:
print(f"[{msg['role']}] {msg['content']}")
# Delete a completion
requests.delete(
f"{base}/chat/completions/chatcmpl-abc123",
headers=headers
)
Node.js (fetch)
const base = "https://api.xerotier.ai/proj_ABC123/my-endpoint/v1";
const headers = {
"Authorization": "Bearer xero_myproject_your_api_key",
"Content-Type": "application/json"
};
// List stored completions
const listRes = await fetch(
`${base}/chat/completions?limit=5&order=desc`,
{ headers }
);
const completions = await listRes.json();
completions.data.forEach(c =>
console.log(`${c.id} - ${c.model} (${c.usage.total_tokens} tokens)`)
);
// Get a specific completion
const compRes = await fetch(
`${base}/chat/completions/chatcmpl-abc123`,
{ headers }
);
const comp = await compRes.json();
console.log(`Model: ${comp.model}`);
// Update completion metadata
await fetch(`${base}/chat/completions/chatcmpl-abc123`, {
method: "POST",
headers,
body: JSON.stringify({
metadata: { env: "production", reviewed: "true" }
})
});
// Get completion messages
const msgsRes = await fetch(
`${base}/chat/completions/chatcmpl-abc123/messages?order=asc`,
{ headers }
);
const messages = await msgsRes.json();
messages.data.forEach(msg =>
console.log(`[${msg.role}] ${msg.content}`)
);
// Delete a completion
await fetch(`${base}/chat/completions/chatcmpl-abc123`, {
method: "DELETE",
headers
});
Error Handling
| HTTP Status | Error Code | Description |
|---|---|---|
| 400 | invalid_request |
Missing or invalid parameters. |
| 401 | authentication_error |
Invalid or missing API key. |
| 404 | completion_not_found |
The specified completion ID does not exist or does not belong to your project. |
| 429 | rate_limit_exceeded |
Too many requests. Check the Retry-After header. |
| 500 | internal_error |
Server-side failure. Retry the request. |