Skip to content

Commit bb2aa1b

Browse files
committed
docs: make README public-facing for CN and BytePlus
## Summary - rewrite the README for public SDK users - document Volcengine China and BytePlus client initialization - organize supported examples under examples/cn and examples/byteplus - use regional Chat, Responses, embedding, image, and video model IDs - remove retired Seededit image-edit examples - omit BytePlus text-only embedding examples, including batch variants, because BytePlus has no model for that endpoint - correct BytePlus IAM comments and environment variable names - keep MCP in both clouds and other hosted built-in tools CN-only with explicit beta headers - add usage and manual migration guidance without internal roadmap language ## Regional model defaults - Responses and Chat: doubao-seed-2-1-pro-260628 / seed-2-0-lite-260428 - Multimodal and sparse embeddings: doubao-embedding-vision-251215 / skylark-embedding-vision-251215 - Image: doubao-seedream-5-0-pro-260628 / dola-seedream-5-0-pro-260628 - Video: doubao-seedance-2-0-fast-260128 / dreamina-seedance-2-0-fast-260128 ## Validation - Python compileall across all regional examples after rebasing onto the latest generated SDK branch - verified no BytePlus text-only embedding call remains - documentation model, link, and whitespace checks See merge request: !81 Sync-Source-Commit: de8e67c2cb82d4cf53f484ce45a65349304479a4 Hand-Written-Reason: Hand-written public documentation and regional examples update; not produced by ark-apis generation. Release-Version: 0.4.0
1 parent ba68b5b commit bb2aa1b

55 files changed

Lines changed: 1941 additions & 184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,71 @@
11
# Ark Runtime Python SDK
22

3-
The official Python library for the Volcengine Ark runtime API. It provides convenient access to the Ark REST API from any Python 3.8+ application, with both synchronous and asynchronous clients.
3+
The official Python library for accessing ModelArk on Volcengine and BytePlus. It provides synchronous and asynchronous clients, typed models, streaming, authentication, retries, and timeout configuration.
44

55
## Installation
66

77
```bash
88
pip install arkruntime
99
```
1010

11-
## Usage
11+
## Choose Volcengine or BytePlus
12+
13+
Set `ARK_API_KEY`, then choose the client factory for the service you use. The factory configures the correct base URL and region; request construction and all subsequent SDK calls are the same.
1214

13-
Create a client by setting the `ARK_API_KEY` environment variable:
15+
### Volcengine (China)
1416

1517
```python
1618
from arkruntime import Ark
1719

18-
client = Ark()
19-
# or explicitly: Ark(api_key="your-api-key")
20+
client = Ark.volc()
21+
# or explicitly: Ark.volc(api_key="your-api-key")
2022
```
2123

24+
### BytePlus (BP)
25+
26+
```python
27+
from arkruntime import Ark
28+
29+
client = Ark.byteplus()
30+
# or explicitly: Ark.byteplus(api_key="your-api-key")
31+
```
32+
33+
Use a model ID available in the corresponding Volcengine or BytePlus account. Model IDs can differ between the two services; the examples use `doubao-seed-2-1-pro-260628` for Volcengine and `seed-2-0-lite-260428` for BytePlus. Override either default with `ARK_MODEL`.
34+
35+
The async client provides the same factories: `AsyncArk.volc()` and `AsyncArk.byteplus()`.
36+
37+
## Quick start
38+
2239
### Responses API
2340

2441
```python
2542
import os
2643
from arkruntime import Ark
2744

28-
client = Ark()
45+
client = Ark.volc()
2946

3047
response = client.responses.create(
3148
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
3249
input="Explain how large language models work in three sentences.",
3350
)
34-
print(response.output_text)
51+
for item in response.output or []:
52+
if item.type == "message":
53+
for content in item.content:
54+
if content.type == "output_text":
55+
print(content.text)
3556
```
3657

58+
For BytePlus, change only the client line to `client = Ark.byteplus()` and set `ARK_MODEL` to a BytePlus model ID.
59+
60+
## Usage
61+
3762
### Chat Completions
3863

3964
```python
4065
import os
4166
from arkruntime import Ark
4267

43-
client = Ark()
68+
client = Ark.volc()
4469

4570
completion = client.chat.completions.create(
4671
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
@@ -62,7 +87,7 @@ Both the Responses and Chat Completions APIs support streaming via `stream=True`
6287
import os
6388
from arkruntime import Ark
6489

65-
client = Ark()
90+
client = Ark.volc()
6691

6792
stream = client.responses.create(
6893
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
@@ -79,7 +104,7 @@ for event in stream:
79104
import os
80105
from arkruntime import Ark
81106

82-
client = Ark()
107+
client = Ark.volc()
83108

84109
stream = client.chat.completions.create(
85110
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
@@ -100,14 +125,18 @@ import asyncio
100125
import os
101126
from arkruntime import AsyncArk
102127

103-
client = AsyncArk()
128+
client = AsyncArk.volc()
104129

105130
async def main():
106131
response = await client.responses.create(
107132
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
108133
input="Explain quantum computing briefly.",
109134
)
110-
print(response.output_text)
135+
for item in response.output or []:
136+
if item.type == "message":
137+
for content in item.content:
138+
if content.type == "output_text":
139+
print(content.text)
111140

112141
asyncio.run(main())
113142
```
@@ -120,7 +149,7 @@ Pass images alongside text using multimodal content blocks.
120149
import os
121150
from arkruntime import Ark
122151

123-
client = Ark()
152+
client = Ark.volc()
124153

125154
completion = client.chat.completions.create(
126155
model=os.environ.get("ARK_MODEL", "doubao-seed-2-1-pro-260628"),
@@ -144,7 +173,7 @@ import json
144173
import os
145174
from arkruntime import Ark
146175

147-
client = Ark()
176+
client = Ark.volc()
148177

149178
tools = [
150179
{
@@ -179,7 +208,7 @@ print(f"Arguments: {tool_call.function.arguments}")
179208
```python
180209
from arkruntime import Ark
181210

182-
client = Ark()
211+
client = Ark.volc()
183212

184213
# Upload a file
185214
file = client.files.create(file=open("data.jsonl", "rb"), purpose="batch")
@@ -201,7 +230,7 @@ The SDK raises typed exceptions for API errors.
201230
from arkruntime import Ark
202231
from arkruntime._exceptions import ArkAPIError, ArkRateLimitError, ArkAuthenticationError
203232

204-
client = Ark()
233+
client = Ark.volc()
205234

206235
try:
207236
client.chat.completions.create(
@@ -243,7 +272,7 @@ The client automatically retries failed requests (default: 2 retries) with backo
243272
from arkruntime import Ark
244273

245274
# Customize retries and timeout
246-
client = Ark(
275+
client = Ark.volc(
247276
max_retries=5,
248277
timeout=120.0, # seconds
249278
)
@@ -266,7 +295,7 @@ client.chat.completions.create(
266295
```python
267296
from arkruntime import Ark
268297

269-
client = Ark(timeout=24 * 3600)
298+
client = Ark.volc(timeout=24 * 3600)
270299

271300
result = client.batch.chat.completions.create(
272301
model="doubao-seed-2-1-pro-260628",
@@ -275,50 +304,18 @@ result = client.batch.chat.completions.create(
275304
print(result)
276305
```
277306

278-
## API coverage
279-
280-
| API | Client path |
281-
|---|---|
282-
| Responses | `client.responses.create()` |
283-
| Chat Completions | `client.chat.completions.create()` |
284-
| Embeddings | `client.embeddings.create()` |
285-
| Multimodal Embeddings | `client.multimodal_embeddings.create()` |
286-
| Content Generation | `client.content_generation.tasks.create()` |
287-
| Images | `client.images.generate()` |
288-
| Files | `client.files.create()` / `.list()` / `.delete()` |
289-
| Tokenization | `client.tokenization.create()` |
290-
| Batch | `client.batch.chat.completions.create()` etc. |
291-
292307
## Examples
293308

294-
See the [examples/](./examples) directory for runnable scripts:
295-
296-
- `responses/` -- Responses API: multi-turn chat, function calling, structured output, video streaming
297-
- `chat/` -- Chat Completions: basic, function calling, reasoning, structured output, vision
298-
- `batch/` -- Batch inference: chat completions, embeddings, multimodal embeddings (sync + async)
299-
- `files/` -- Files API: upload, wait for processing, list, delete
300-
- `embeddings.py` -- Text embeddings
301-
- `multimodal_embeddings.py` -- Multimodal embeddings with image input
302-
- `content_generation_tasks.py` -- Video generation task lifecycle
303-
- `image_generations.py` -- Image generation
304-
- `tokenization.py` -- Tokenization API
305-
306-
## Development
309+
For detailed usage guidance and legacy migration, see
310+
[`docs/README.md`](docs/README.md) and
311+
[`docs/migration.md`](docs/migration.md).
307312

308-
This repo uses [uv](https://docs.astral.sh/uv/) for dependency management.
309-
310-
```bash
311-
uv sync # create venv + install runtime + dev deps
312-
uv run pytest # run tests
313-
uv run ruff check src/ # lint
314-
uv run ruff format src/ # format
315-
```
313+
See the [examples/](./examples) directory for runnable scripts:
316314

317-
A pre-commit hook runs the same linting as CI:
315+
- `volc/` -- Volcengine China examples for Chat, Responses, images, video generation, embeddings, files, tokenization, batch APIs, and resource APIs
316+
- `byteplus/` -- supported BytePlus counterparts using the BytePlus client and regional model IDs
318317

319-
```bash
320-
uv run pre-commit install # one-time setup
321-
```
318+
MCP examples are provided for both clouds and explicitly send `ark-beta-mcp: true`. Other built-in-tool examples are CN-only and show their required beta headers.
322319

323320
## Requirements
324321

docs/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Ark Runtime Python SDK documentation
2+
3+
This directory contains detailed usage and migration guidance for the Ark
4+
Runtime Python SDK.
5+
6+
## Choose the right document
7+
8+
- [Usage guide](usage.md): installation, regional clients,
9+
request bodies, sync/async streaming, output parsing, and built-in tools.
10+
- [Migration guide](migration.md): migrate from the legacy Volcengine or
11+
BytePlus Python SDK.
12+
- [`../examples/volc`](../examples/volc): runnable Volcengine examples.
13+
- [`../examples/byteplus`](../examples/byteplus): runnable BytePlus examples.
14+
15+
## Important usage rules
16+
17+
1. Create clients with `Ark.volc()` / `AsyncArk.volc()` for CN or
18+
`Ark.byteplus()` / `AsyncArk.byteplus()` for BytePlus. Do not supply a CN URL
19+
to a BytePlus client or the reverse.
20+
2. Keep credentials in `ARK_API_KEY`; never place a key in code, prompts,
21+
generated patches, tests, logs, or notebooks.
22+
3. Preserve the documented request body shape and type discriminators. A dict
23+
union member needs the correct `type`, field names, and nesting.
24+
4. Streaming APIs return events or chunks, not the final response object.
25+
Handle only the event types needed and safely ignore other valid events.
26+
5. A non-streaming Responses object has no `response.output_text` convenience
27+
field. Traverse `response.output`, message content, and `output_text` items.
28+
6. MCP works in CN and BytePlus. Other hosted built-in tools shown here are
29+
CN-only and require their matching `ark-beta-*` header.
30+
31+
## Minimal verification
32+
33+
```bash
34+
python -m compileall src examples
35+
python -m pytest
36+
```
37+
38+
Also run one non-streaming and one streaming call in the intended cloud. Test
39+
each built-in tool independently so missing access or headers cannot be hidden
40+
by a successful ordinary request.

0 commit comments

Comments
 (0)