Files

Quickstart

Upload, list, download and delete with the OpenAI Python SDK.

Install the SDK and set PRAXIS_API_KEY to your API key. Save the Python code as files.py.

For Develop, also set PRAXIS_API_BASE=https://api-develop.deepraxis.ai. Without this variable, the example uses the production API. Use a key for the selected environment.

python -m pip install openai
python files.py
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PRAXIS_API_KEY"],
    base_url=os.environ.get("PRAXIS_API_BASE", "https://api.deepraxis.com") + "/openai/v1",
)
file = client.files.create(
    file=("hello.txt", b"Hello, Praxis!\n", "text/plain"),
    purpose="user_data",
    expires_after={"anchor": "created_at", "seconds": 3600},
)
try:
    print("uploaded:", file.id)
    files = client.files.list(limit=100)
    print("listed:", any(item.id == file.id for item in files))
    content = client.files.content(file.id).read()
    assert content == b"Hello, Praxis!\n"
    print("downloaded:", content.decode().strip())
finally:
    deleted = client.files.delete(file.id)
    print("deleted:", deleted.deleted)

Expected: an uploaded ID, listed: True, downloaded: Hello, Praxis! and deleted: True. The example deletes its file even if listing or downloading fails.

API reference → · Cookbook →

Export

On this page

No Headings