path_template URL-encodes slashes in model name, breaking ai.run() in v5

Open Beginner friendly
#2,718 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
api

Research direction

Start in cloudflare._utils.path_template and trace the client.ai.run entry point using the reproduction model name. Verify the generated path against the expected unsplit model path, then add or update focused coverage so slash-containing model identifiers produce the expected route without breaking ordinary parameters.

Written by the indexing model from the issue text.

Description

Confirm this is a Python library issue and not an underlying Cloudflare API issue.
  • 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:

{
  "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

from cloudflare import Cloudflare

client = Cloudflare(api_token="<valid_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="<account_id>",
    prompt="a cat sitting on a chair",
)

I also confirmed the encoding without making an API call:

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:

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
from cloudflare import Cloudflare

client = Cloudflare(api_token="<valid_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="<account_id>",
    prompt="a cat sitting on a chair",
)
Code snippets

OS

Linux Fedora

Python version

3.12

Library version

5.1.0

Dominant language
Python
Stars
509
Forks
150
Avg merge
3h 15m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/cloudflare-python

All issues in cloudflare/cloudflare-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.