cloudflare / cloudflare/cloudflare-python
path_template URL-encodes slashes in model name, breaking ai.run() in v5
- 主要語言
- Python
- 星號
- 509
- 分支
- 150
- 平均合併
- 3 小時 15 分鐘
- 30 天內合併 PR
- 1
描述
### Confirm this is a Python library issue and not an underlying Cloudflare API issue.
- [x] This is an issue with the Python library
### Describe the bug
# Bug: `path_template` URL-encodes slashes in model name, breaking `ai.run()` in v5
## Description
After upgrading from `cloudflare` Python SDK v4.3.1 to v5.x, my calls to `client.ai.run()` fail with a `400` error:
```json
{
"success": false,
"errors": [{"code": 7000, "message": "No route for that URI"}],
"messages": [],
"result": null
}
```
The root cause seems to be that `path_template()` URL-encodes the forward slashes (`/` → `%2F`) in the `model_name` parameter, producing an invalid API path.
## Expected path
```
/accounts/{account_id}/ai/run/@cf/black-forest-labs/flux-1-schnell
```
## Actual path (v5)
```
/accounts/{account_id}/ai/run/@cf%2Fblack-forest-labs%2Fflux-1-schnell
```
## Reproduction
```python
from cloudflare import Cloudflare
client = Cloudflare(api_token="")
# This worked in v4.3.1, fails in v5 with "No route for that URI"
result = client.ai.run(
"@cf/black-forest-labs/flux-1-schnell",
account_id="",
prompt="a cat sitting on a chair",
)
```
I also confirmed the encoding without making an API call:
```python
from cloudflare._utils import path_template
path = path_template(
"/accounts/{account_id}/ai/run/{model_name}",
account_id="test123",
model_name="@cf/black-forest-labs/flux-1-schnell",
)
print(path)
# Output: /accounts/test123/ai/run/@cf%2Fblack-forest-labs%2Fflux-1-schnell
# Expected: /accounts/test123/ai/run/@cf/black-forest-labs/flux-1-schnell
```
## Environment
- **SDK version:** 5.0.0 / 5.1.0 (both affected)
- **Python:** 3.12
- **OS:** Ubuntu 24 (GitHub Actions runner) — also reproducible locally
- **Last working version:** 4.3.1
## Impact
This breaks **every** `client.ai.run()` call for any model which identifiers contain slashes (e.g. `@cf/meta/llama-3.1-8b-instruct`, `@cf/black-forest-labs/flux-1-schnell`, etc.).
## Workaround
In the meantime, I am using a workaround based on the REST API directly to bypass the SDK:
```python
import requests
response = requests.post(
f"https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/@cf/black-forest-labs/flux-1-schnell",
headers={"Authorization": f"Bearer {api_token}"},
json={"prompt": "a cat sitting on a chair"},
)
data = response.json()
```
### To Reproduce
```python
from cloudflare import Cloudflare
client = Cloudflare(api_token="")
# This worked in v4.3.1, fails in v5 with "No route for that URI"
result = client.ai.run(
"@cf/black-forest-labs/flux-1-schnell",
account_id="",
prompt="a cat sitting on a chair",
)
```
### Code snippets
```Python
```
### OS
Linux Fedora
### Python version
3.12
### Library version
5.1.0
貢獻指南
研究方向
從 cloudflare._utils.path_template 開始,使用重現中的模型名稱追蹤 client.ai.run 進入點。將產生的路徑與預期的未分割模型路徑進行核對,然後新增或更新有針對性的覆蓋,讓包含斜線的模型識別碼產生預期的路由,同時不破壞一般參數。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 65/100