/batches
Umfasst Batches, Dateien
| Feature | UnterstĂĽtzt | Notizen |
|---|---|---|
| UnterstĂĽtzte Anbieter | OpenAI, Azure, Vertex | - |
| ✨ Kostenverfolgung | ✅ | Nur LiteLLM Enterprise |
| Protokollierung | âś… | Funktioniert ĂĽber alle Logging-Integrationen hinweg |
Schnellstart​
Datei fĂĽr Batch-Abschluss erstellen
Batch-Anfrage erstellen
Batches auflisten
Spezifischen Batch und Dateiinhalt abrufen
- LITELLM PROXY SERVER
- SDK
$ export OPENAI_API_KEY="sk-..."
$ litellm
# RUNNING on http://0.0.0.0:4000
Datei fĂĽr Batch-Abschluss erstellen
curl https://:4000/v1/files \
-H "Authorization: Bearer sk-1234" \
-F purpose="batch" \
-F file="@mydata.jsonl"
Batch-Anfrage erstellen
curl https://:4000/v1/batches \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
-d '{
"input_file_id": "file-abc123",
"endpoint": "/v1/chat/completions",
"completion_window": "24h"
}'
Spezifischen Batch abrufen
curl https://:4000/v1/batches/batch_abc123 \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
Batches auflisten
curl https://:4000/v1/batches \
-H "Authorization: Bearer sk-1234" \
-H "Content-Type: application/json" \
Datei fĂĽr Batch-Abschluss erstellen
from litellm
import os
os.environ["OPENAI_API_KEY"] = "sk-.."
file_name = "openai_batch_completions.jsonl"
_current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(_current_dir, file_name)
file_obj = await litellm.acreate_file(
file=open(file_path, "rb"),
purpose="batch",
custom_llm_provider="openai",
)
print("Response from creating file=", file_obj)
Batch-Anfrage erstellen
from litellm
import os
create_batch_response = await litellm.acreate_batch(
completion_window="24h",
endpoint="/v1/chat/completions",
input_file_id=batch_input_file_id,
custom_llm_provider="openai",
metadata={"key1": "value1", "key2": "value2"},
)
print("response from litellm.create_batch=", create_batch_response)
Spezifischen Batch und Dateiinhalt abrufen
retrieved_batch = await litellm.aretrieve_batch(
batch_id=create_batch_response.id, custom_llm_provider="openai"
)
print("retrieved batch=", retrieved_batch)
# just assert that we retrieved a non None batch
assert retrieved_batch.id == create_batch_response.id
# try to get file content for our original file
file_content = await litellm.afile_content(
file_id=batch_input_file_id, custom_llm_provider="openai"
)
print("file content = ", file_content)
Batches auflisten
list_batches_response = litellm.list_batches(custom_llm_provider="openai", limit=2)
print("list_batches_response=", list_batches_response)
Unterstützte Anbieter:​
Azure OpenAI​
OpenAI​
Vertex AI​
Wie die Kostenverfolgung für Batches-APIs funktioniert​
LiteLLM verfolgt die Kosten der Batch-Verarbeitung, indem es zwei SchlĂĽsselereignisse protokolliert
| Ereignistyp | Beschreibung | Wann es protokolliert wird |
|---|---|---|
acreate_batch | Erstellung des ersten Batches | Wenn die Batch-Anfrage ĂĽbermittelt wird |
batch_success | EndgĂĽltige Nutzung und Kosten | Wenn die Batch-Verarbeitung abgeschlossen ist |
Kostenberechnung
- LiteLLM prĂĽft den Batch-Status bis zur Fertigstellung
- Nach Abschluss aggregiert es die Nutzung und Kosten aus allen Antworten in der Ausgabedatei
tokenundresponse_costinsgesamt spiegeln die kombinierten Metriken aller Batch-Antworten wider