Skip to content

Commit f015dfc

Browse files
Zawwarsami16claude
andcommitted
docs: fix openai-py base_url examples (must include /v1)
live testing surfaced — openai-py library appends /chat/completions to base_url, so base_url must include /v1. previously docs showed: base_url="https://hub.example.com/zai" which produces a 404 since the hub serves /zai/v1/chat/completions. correct usage shown now in: - README.md (added a 'Calling from the OpenAI Python library' subsection with both non-streaming and streaming examples) - examples/ZAI_PUBLISH.md (corrected and called out the /v1 requirement explicitly) verified live: openai-py 1.x against zhub hub, both stream=False and stream=True paths work cleanly when /v1 is in base_url. signed manifest fetch + external verify also confirmed working — verify_manifest() returns True against /<name>/manifest.json fetched over HTTP. key pinning verified live: stolen api_key + new ed25519 keypair → hub returns 'register_failed: key pinning: stored public_key does not match'. attacker with just an api_key cannot take over a signed publisher. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 28d9328 commit f015dfc

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ python examples/orchestrate_demo.py
6060

6161
The AI saw a connection arrive, registered its capabilities, and invoked them at the user's request — all through the hub, in a single conversation.
6262

63+
### Calling from the OpenAI Python library
64+
65+
```python
66+
from openai import OpenAI
67+
68+
# IMPORTANT: openai-py expects /v1 in the base_url.
69+
# Use ".../<name>/v1", not just ".../<name>".
70+
client = OpenAI(
71+
base_url="http://localhost:8080/echo/v1",
72+
api_key="zk_...",
73+
)
74+
client.chat.completions.create(model="echo", messages=[{"role":"user","content":"hi"}])
75+
# streaming works too:
76+
for chunk in client.chat.completions.create(
77+
model="echo", messages=[...], stream=True,
78+
):
79+
print(chunk.choices[0].delta.content or "", end="", flush=True)
80+
```
81+
6382
---
6483

6584
## Install

examples/ZAI_PUBLISH.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ curl https://<hub>.trycloudflare.com/zai/v1/chat/completions \
7070
```python
7171
from openai import OpenAI
7272

73+
# IMPORTANT: openai-py expects /v1 in the base_url. Use ".../zai/v1", not ".../zai".
7374
client = OpenAI(
74-
base_url="https://<hub>.trycloudflare.com/zai",
75+
base_url="https://<hub>.trycloudflare.com/zai/v1",
7576
api_key="zk_a8f2c9d3...",
7677
)
7778

0 commit comments

Comments
 (0)