# 快速开始 (/docs/cloud/services/file/quickstart)



安装 SDK，并将 API Key 设置在环境变量 `PRAXIS_API_KEY` 中。把下面的 Python 代码保存为 `files.py`。

使用 Develop 时，另设 `PRAXIS_API_BASE=https://api-develop.deepraxis.ai`；未设置时使用正式 API。Key 必须属于所选环境。

```bash
python -m pip install openai
python files.py
```

```python
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.ai") + "/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)
```

期望：输出上传的 ID、`listed: True`、`downloaded: Hello, Praxis!` 和 `deleted: True`。即使列出或下载失败，示例也会删除自己创建的文件。

[API 参考 →](/docs/api/native/file) · [Cookbook →](/docs/cookbook)
