@acedatacloud/skills 2026.630.0 → 2026.630.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acedatacloud/skills",
3
- "version": "2026.630.0",
3
+ "version": "2026.630.2",
4
4
  "description": "Agent Skills for AceDataCloud AI services — music, image, video generation, LLM chat, web search. Compatible with Claude Code, GitHub Copilot, Gemini CLI, OpenAI Codex, and 30+ AI coding agents.",
5
5
  "keywords": [
6
6
  "agent-skills",
@@ -1,113 +1,81 @@
1
1
  ---
2
2
  name: ai-chat
3
- description: Access 50+ LLM models through a unified OpenAI-compatible API via AceDataCloud. Use when you need chat completions from GPT, Claude, Gemini, Kimi, Grok, or other models through a single endpoint. Supports streaming, function calling, and vision.
3
+ description: Access 50+ LLM models through AceDataCloud's unified chat APIs. Use when you need OpenAI-compatible chat/responses calls or the newer `/aichat2/conversations` API across GPT, Claude, Gemini, Grok, Kimi, GLM, and DeepSeek models. Supports streaming, multimodal input, and tool calling.
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: acedatacloud
7
7
  version: "1.0"
8
- compatibility: Requires ACEDATACLOUD_API_TOKEN in .env file (see _shared/authentication.md). Works as a drop-in replacement for the OpenAI SDK.
8
+ compatibility: Requires ACEDATACLOUD_API_TOKEN in .env file (see _shared/authentication.md). Works with OpenAI-compatible SDKs against the `/openai/*` routes.
9
9
  ---
10
10
 
11
11
  # AI Chat — Unified LLM Gateway
12
12
 
13
- Access 50+ language models through a single OpenAI-compatible endpoint via AceDataCloud.
13
+ AceDataCloud exposes two documented chat surfaces:
14
+
15
+ | Endpoint | Use For |
16
+ |----------|---------|
17
+ | `POST /aichat2/conversations` | Recommended stateful / multimodal / agentic conversations |
18
+ | `POST /aichat/conversations` | Legacy conversation endpoint |
19
+ | `POST /openai/chat/completions` | OpenAI-compatible stateless chat completions |
20
+ | `POST /openai/responses` | OpenAI-compatible responses API |
14
21
 
15
22
  > **Setup:** See [authentication](../_shared/authentication.md) for token setup.
16
23
 
17
24
  ## Quick Start
18
25
 
26
+ ### Recommended: stateful conversations
27
+
19
28
  ```bash
20
- curl -X POST https://api.acedata.cloud/v1/chat/completions \
21
- -H "Authorization: Bearer $ACEDATACLOUD_API_TOKEN" \
29
+ curl -X POST https://api.acedata.cloud/aichat2/conversations \
30
+ -H "Authorization: ******ACEDATACLOUD_API_TOKEN" \
22
31
  -H "Content-Type: application/json" \
23
- -d '{"model": "claude-sonnet-4-20250514", "messages": [{"role": "user", "content": "Hello!"}]}'
32
+ -d '{"model":"gpt-4.1","question":"Summarize the latest release notes.","stateful":true}'
24
33
  ```
25
34
 
26
- ## OpenAI SDK Drop-in
35
+ ### OpenAI-compatible SDK
27
36
 
28
37
  ```python
29
38
  from openai import OpenAI
30
39
 
31
40
  client = OpenAI(
32
41
  api_key="your-token-here",
33
- base_url="https://api.acedata.cloud/v1"
42
+ base_url="https://api.acedata.cloud/openai"
34
43
  )
35
44
 
36
45
  response = client.chat.completions.create(
37
- model="gpt-4.1",
46
+ model="gpt-5.5",
38
47
  messages=[{"role": "user", "content": "Explain quantum computing"}]
39
48
  )
40
49
  print(response.choices[0].message.content)
41
50
  ```
42
51
 
43
- ## Available Models
44
-
45
- ### OpenAI GPT
46
-
47
- | Model | Type | Best For |
48
- |-------|------|----------|
49
- | `gpt-4.1` | Latest | General-purpose, high quality |
50
- | `gpt-4.1-mini` | Small | Fast, cost-effective |
51
- | `gpt-4.1-nano` | Tiny | Ultra-fast, lowest cost |
52
- | `gpt-4o` | Multimodal | Vision + text |
53
- | `gpt-4o-mini` | Small multimodal | Fast vision tasks |
54
- | `o1` | Reasoning | Complex reasoning tasks |
55
- | `o1-mini` | Small reasoning | Quick reasoning |
56
- | `o1-pro` | Pro reasoning | Advanced reasoning |
57
- | `gpt-5` | Latest gen | Next-gen intelligence |
58
- | `gpt-5.4` | Gen 5.4 | High-performance next-gen |
59
- | `gpt-5-mini` | Mini gen 5 | Fast next-gen |
60
-
61
- ### Anthropic Claude
62
-
63
- | Model | Type | Best For |
64
- |-------|------|----------|
65
- | `claude-opus-4-8` | Latest Opus | Highest capability |
66
- | `claude-opus-4-6` | Latest Opus | Highest capability |
67
- | `claude-sonnet-4-6` | Latest Sonnet | Balanced quality/speed |
68
- | `claude-opus-4-5-20251101` | Opus 4.5 | Premium tasks |
69
- | `claude-sonnet-4-5-20250929` | Sonnet 4.5 | High-quality balance |
70
- | `claude-sonnet-4-20250514` | Sonnet 4 | Reliable general-purpose |
71
- | `claude-haiku-4-5-20251001` | Haiku 4.5 | Fast, efficient |
72
- | `claude-3-5-sonnet-20241022` | Legacy 3.5 | Proven track record |
73
- | `claude-3-opus-20240229` | Legacy Opus | Maximum quality (legacy) |
74
-
75
- ### Google Gemini
76
-
77
- | Model | Best For |
78
- |-------|----------|
79
- | `gemini-1.5-pro` | Long context, complex tasks |
80
- | `gemini-1.5-flash` | Fast, efficient |
81
-
82
- ### xAI Grok
83
-
84
- | Model | Best For |
85
- |-------|----------|
86
- | `grok-4` | Latest, highest capability |
87
- | `grok-3` | General-purpose |
88
- | `grok-3-fast` | Speed-optimized |
89
- | `grok-3-mini` | Compact, efficient |
90
-
91
- ## Features
92
-
93
- ### Streaming
52
+ ## Currently Documented Model Families
94
53
 
95
- ```json
96
- POST /v1/chat/completions
97
- {
98
- "model": "claude-sonnet-4-20250514",
99
- "messages": [{"role": "user", "content": "Write a story"}],
100
- "stream": true
101
- }
102
- ```
54
+ The OpenAPI specs expose a broad, fast-moving model catalog. Representative current
55
+ models include:
56
+
57
+ | Family | Current examples |
58
+ |--------|------------------|
59
+ | OpenAI / reasoning | `gpt-5.5`, `gpt-5.5-pro`, `gpt-5.4`, `gpt-5.4-pro`, `gpt-5.2`, `gpt-5.1`, `gpt-5`, `gpt-5-mini`, `gpt-5-nano`, `gpt-4.1`, `gpt-4.1-mini`, `gpt-4.1-nano`, `gpt-4o`, `gpt-4o-mini`, `o1`, `o3`, `o4-mini` |
60
+ | OpenAI free-tier chat-completions | `gpt-5.5:free`, `gpt-5:free`, `gpt-4.1:free`, `gpt-4o:free`, `gpt-4o-mini:free`, `gpt-oss:free` |
61
+ | Claude | `claude-opus-4-8`, `claude-opus-4-7`, `claude-opus-4-6`, `claude-opus-4-5-20251101`, `claude-sonnet-4-6`, `claude-sonnet-4-5-20250929`, `claude-sonnet-4-20250514`, `claude-haiku-4-5-20251001`, `claude-3-7-sonnet-20250219` |
62
+ | Gemini | `gemini-3.1-pro`, `gemini-3.1-pro-preview`, `gemini-3.1-flash-image-preview`, `gemini-3.1-flash-lite-preview`, `gemini-3-pro-preview`, `gemini-2.5-flash-lite`, `gemini-2.0-flash-lite` |
63
+ | Grok | `grok-4`, `grok-4-0709`, `grok-3`, `grok-3-fast` |
64
+ | DeepSeek | `deepseek-r1`, `deepseek-r1-0528`, `deepseek-v3`, `deepseek-v3-250324`, `deepseek-v3.2-exp`, `deepseek-v4-flash` |
65
+ | Kimi | `kimi-k2.5`, `kimi-k2-thinking-turbo`, `kimi-k2-thinking`, `kimi-k2-instruct-0905`, `kimi-k2-0905-preview`, `kimi-k2-turbo-preview`, `kimi-k2-0711-preview` |
66
+ | GLM | `glm-5.2`, `glm-5.1`, `glm-5`, `glm-5-turbo`, `glm-4.7`, `glm-4.6`, `glm-4.5`, `glm-4.5v`, `glm-3-turbo` |
67
+
68
+ `/aichat2/conversations` also accepts `model_group` values
69
+ `chatgpt`, `claude`, `gemini`, `grok`, `kimi`, `glm`, and `deepseek`.
103
70
 
104
- ### Function Calling
71
+ ## OpenAI-Compatible Chat
105
72
 
106
73
  ```json
107
- POST /v1/chat/completions
74
+ POST /openai/chat/completions
108
75
  {
109
76
  "model": "gpt-4.1",
110
- "messages": [{"role": "user", "content": "What's the weather in Tokyo?"}],
77
+ "messages": [{"role": "user", "content": "Write a haiku about observability."}],
78
+ "stream": true,
111
79
  "tools": [
112
80
  {
113
81
  "type": "function",
@@ -120,84 +88,61 @@ POST /v1/chat/completions
120
88
  }
121
89
  ```
122
90
 
123
- ### Vision
124
-
125
- ```json
126
- POST /v1/chat/completions
127
- {
128
- "model": "gpt-4o",
129
- "messages": [
130
- {
131
- "role": "user",
132
- "content": [
133
- {"type": "text", "text": "What's in this image?"},
134
- {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
135
- ]
136
- }
137
- ]
138
- }
139
- ```
140
-
141
- ## Parameters
91
+ Common parameters:
142
92
 
143
93
  | Parameter | Type | Description |
144
94
  |-----------|------|-------------|
145
- | `model` | string | Model name (see tables above) |
146
- | `messages` | array | Array of `{role, content}` objects |
147
- | `temperature` | 0–2 | Randomness (default: 1) |
148
- | `top_p` | 0–1 | Nucleus sampling |
149
- | `max_tokens` | integer | Maximum output tokens |
95
+ | `model` | string | One of the documented OpenAI-compatible models |
96
+ | `messages` | array | Standard OpenAI chat message list |
97
+ | `temperature` / `top_p` | number | Sampling controls |
98
+ | `max_tokens` | integer | Output cap |
150
99
  | `stream` | boolean | Enable SSE streaming |
151
- | `tools` | array | Function calling definitions |
152
- | `tool_choice` | string/object | Tool selection strategy |
100
+ | `tools` / `tool_choice` | array / string-object | Function-calling controls |
101
+ | `service_tier` | string | Processing tier (`auto`, `default`, `flex`, `scale`, `priority`) |
102
+
103
+ ## Stateful / Agentic Conversations
153
104
 
154
- ## Response
105
+ `POST /aichat2/conversations` generalizes the legacy conversation API with
106
+ multimodal user content, CRUD-style actions, and server-side conversation state.
155
107
 
156
108
  ```json
109
+ POST /aichat2/conversations
157
110
  {
158
- "id": "chatcmpl-xxx",
159
- "object": "chat.completion",
160
- "model": "claude-sonnet-4-20250514",
161
- "choices": [
162
- {
163
- "index": 0,
164
- "message": {"role": "assistant", "content": "Hello!"},
165
- "finish_reason": "stop"
166
- }
111
+ "action": "chat",
112
+ "model": "claude-sonnet-4-6",
113
+ "message": [
114
+ {"type": "text", "text": "Describe this image."},
115
+ {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
167
116
  ],
168
- "usage": {
169
- "prompt_tokens": 10,
170
- "completion_tokens": 5,
171
- "total_tokens": 15
172
- }
117
+ "stateful": true,
118
+ "allowed_skills": ["google-search"],
119
+ "allowed_mcp_servers": ["mcp-google-search"]
173
120
  }
174
121
  ```
175
122
 
176
- ## Gotchas
177
-
178
- - **100% OpenAI-compatible** — use the standard OpenAI SDK with `base_url="https://api.acedata.cloud/v1"`
179
- - Billing is token-based with per-model pricing (more expensive models cost more per token)
180
- - Vision is supported on multimodal models (`gpt-4o`, `gpt-4o-mini`, `grok-2-vision-*`)
181
- - Function calling works on most modern models (GPT-4+, Claude 3+)
182
- - Streaming returns `chat.completion.chunk` objects via SSE
183
- - `finish_reason` values: `"stop"` (complete), `"length"` (max tokens), `"tool_calls"` (function call), `"content_filter"` (filtered)
184
-
185
- ## Stateful Conversations Endpoint
186
-
187
- For stateful, session-based chat (no need to send the full history each time), use `POST /aichat2/conversations` (recommended). `POST /aichat/conversations` remains available for legacy compatibility.
188
-
189
- ```bash
190
- curl -X POST https://api.acedata.cloud/aichat2/conversations \
191
- -H "Authorization: Bearer $ACEDATACLOUD_API_TOKEN" \
192
- -H "Content-Type: application/json" \
193
- -d '{"model": "gpt-4.1", "question": "What is quantum computing?", "stateful": true}'
194
- ```
123
+ Useful parameters:
195
124
 
196
125
  | Parameter | Type | Description |
197
126
  |-----------|------|-------------|
198
- | `model` | string | Model name (see Available Models above) |
199
- | `question` | string | The prompt or question to answer |
200
- | `id` | string | Conversation ID pass the same ID to continue a session |
201
- | `preset` | string | Preset/system prompt for the conversation |
202
- | `stateful` | boolean | Enable stateful conversation (maintains history server-side) |
203
- | `references` | array | Additional context documents to include |
127
+ | `action` | string | `chat`, `retrieve`, `retrieve_batch`, `update`, `delete` |
128
+ | `model` | string | Model name |
129
+ | `question` | string | Simple text prompt |
130
+ | `message` | string or array | Multimodal content using `text`, `image_url`, or `file_url` items |
131
+ | `stateful` | boolean | Keep conversation history server-side |
132
+ | `references` | array | Extra context documents |
133
+ | `preset` | string | Preset/system prompt |
134
+ | `max_turns` | integer | Trim retained turn history |
135
+ | `allowed_skills` / `allowed_mcp_servers` | array | Restrict tool-use scope |
136
+ | `unattended_policy` | object | Tool-use permission policy |
137
+ | `tool_results` | array | Return results for previously requested tool calls |
138
+ | `model_group` | string | Family selector (`chatgpt`, `claude`, `gemini`, `grok`, `kimi`, `glm`, `deepseek`) |
139
+ | `offset` / `limit` | integer | Pagination for retrieval actions |
140
+ | `callback_url` / `async` | string / boolean | Async execution |
141
+
142
+ ## Gotchas
143
+
144
+ - The documented OpenAI-compatible routes live under `/openai/*`, not `/v1/*`.
145
+ - `POST /aichat2/conversations` is the recommended stateful endpoint; `POST /aichat/conversations` remains for legacy clients.
146
+ - `message` on `/aichat2/conversations` can be multimodal (`text`, `image_url`, `file_url`); plain `question` still works for simple text prompts.
147
+ - `action` on `/aichat2/conversations` is not chat-only — it also supports `retrieve`, `retrieve_batch`, `update`, and `delete`.
148
+ - Free-tier model variants such as `gpt-5.5:free` are documented on `/openai/chat/completions`.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: fish-audio
3
- description: Generate AI text-to-speech audio and clone voices with Fish Audio via AceDataCloud API. Use when creating voiceover/narration audio (TTS), synthesizing speech, or cloning a reference voice. Chinese + multilingual.
3
+ description: Generate AI text-to-speech audio with Fish Audio and browse public reference voices via AceDataCloud API. Use when creating voiceover/narration audio (TTS), synthesizing multilingual speech, or selecting a Fish reference voice from the model catalog.
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: acedatacloud
@@ -8,76 +8,111 @@ metadata:
8
8
  compatibility: Requires ACEDATACLOUD_API_TOKEN in .env file (see _shared/authentication.md).
9
9
  ---
10
10
 
11
- # Fish Audio — Text-to-Speech & Voice Cloning
11
+ # Fish Audio — Text-to-Speech
12
12
 
13
- Generate narration / voiceover and clone voices through AceDataCloud's Fish Audio API.
13
+ Generate narration / voiceover through AceDataCloud's Fish Audio API.
14
14
 
15
15
  > **Setup:** See [authentication](../_shared/authentication.md) for token setup.
16
16
 
17
- ## Quick Start (TTS — synchronous, ~3s)
17
+ ## Quick Start
18
18
 
19
19
  ```bash
20
- curl -X POST https://api.acedata.cloud/fish/audios \
21
- -H "Authorization: Bearer $ACEDATACLOUD_API_TOKEN" \
20
+ curl -X POST https://api.acedata.cloud/fish/tts \
21
+ -H "Authorization: ******ACEDATACLOUD_API_TOKEN" \
22
22
  -H "Content-Type: application/json" \
23
- -d '{"action":"speech","model":"fish-tts","voice_id":"543e4181d81b4ef6874b0e8fbdf27c78","prompt":"你好,欢迎使用 AceData Cloud。"}'
23
+ -H "model: s2-pro" \
24
+ -d '{"text":"你好,欢迎使用 AceData Cloud。","reference_id":"d7900c21663f485ab63ebdb7e5905036","format":"mp3"}'
24
25
  ```
25
26
 
26
- Response (synchronous no polling needed for `speech`):
27
+ Synchronous responses return a direct audio URL:
27
28
 
28
29
  ```json
29
- {"success": true, "data": [{"audio_url": "https://platform.r2.fish.audio/task/....mp3"}]}
30
+ {"audio_url":"https://platform.r2.fish.audio/task/8a72ff9840234006a9f74cb2fa04f978.mp3"}
30
31
  ```
31
32
 
32
- → download `data[0].audio_url`. `voice_id` is **required**. A good default Mandarin
33
- news-anchor voice is **`543e4181d81b4ef6874b0e8fbdf27c78`**.
34
-
35
33
  ## Endpoints
36
34
 
37
35
  | Endpoint | Purpose |
38
36
  |----------|---------|
39
- | `POST /fish/audios` | TTS (`action: "speech"`) synchronous |
40
- | `POST /fish/voices` | List / register (clone) voices |
37
+ | `POST /fish/tts` | Text-to-speech generation |
38
+ | `GET /fish/model` | Browse/search public Fish reference voices |
39
+ | `POST /fish/tasks` | Poll async TTS jobs when `async: true` |
41
40
 
42
41
  ## Workflows
43
42
 
44
- ### 1. Text-to-Speech (the common case)
43
+ ### 1. Find a reference voice
44
+
45
+ ```bash
46
+ curl "https://api.acedata.cloud/fish/model?page_size=10&page_number=1&title=Marcus" \
47
+ -H "Authorization: ******ACEDATACLOUD_API_TOKEN"
48
+ ```
49
+
50
+ The response includes `items[]` with public voice metadata such as `_id`, `title`,
51
+ `languages`, `tags`, `visibility`, and `state`. Use an item `_id` as
52
+ `reference_id` in TTS requests.
53
+
54
+ ### 2. Text-to-Speech
45
55
 
46
56
  ```json
47
- POST /fish/audios
57
+ POST /fish/tts
58
+ Headers:
59
+ model: s2-pro
60
+
48
61
  {
49
- "action": "speech",
50
- "model": "fish-tts",
51
- "voice_id": "543e4181d81b4ef6874b0e8fbdf27c78",
52
- "prompt": "你的旁白文本。"
62
+ "text": "Your narration text.",
63
+ "reference_id": "d7900c21663f485ab63ebdb7e5905036",
64
+ "format": "mp3"
53
65
  }
54
66
  ```
55
67
 
56
- ### 2. Clone a voice from a reference sample
68
+ ### 3. Async TTS
57
69
 
58
70
  ```json
59
- POST /fish/voices
71
+ POST /fish/tts
72
+ Headers:
73
+ model: s1
74
+
60
75
  {
61
- "voice_url": "https://example.com/reference-voice.mp3",
62
- "title": "My Custom Voice",
63
- "description": "Clear, neutral-toned speaker"
76
+ "text": "Longer narration for background processing.",
77
+ "async": true,
78
+ "callback_url": "https://api.acedata.cloud/health"
64
79
  }
65
80
  ```
66
81
 
67
- Then pass the returned id as `voice_id` in workflow 1.
82
+ > **Async:** See [async task polling](../_shared/async-tasks.md). Poll via `POST /fish/tasks` with `{"id":"..."}`.
83
+
84
+ ## Parameters — `/fish/tts`
85
+
86
+ ### Header
87
+
88
+ | Parameter | Values | Description |
89
+ |-----------|--------|-------------|
90
+ | `model` | `"s1"`, `"s2-pro"` | Fish TTS engine selection |
68
91
 
69
- ## Parameters — `/fish/audios`
92
+ ### JSON body
70
93
 
71
- | Parameter | Type | Required | Description |
72
- |-----------|------|----------|-------------|
73
- | `action` | string | yes | Use `"speech"` for TTS |
74
- | `model` | string | yes | `"fish-tts"` |
75
- | `voice_id` | string | yes | A Fish reference/cloned voice id (default Mandarin: `543e4181d81b4ef6874b0e8fbdf27c78`) |
76
- | `prompt` | string | yes | Text to synthesize |
94
+ | Parameter | Type / Values | Description |
95
+ |-----------|---------------|-------------|
96
+ | `text` | string | Text to synthesize (required) |
97
+ | `reference_id` | string | Public/reference voice ID from `GET /fish/model` |
98
+ | `format` | `"mp3"`, `"wav"`, `"pcm"`, `"opus"` | Output format |
99
+ | `sample_rate` | integer | Optional output sample rate |
100
+ | `mp3_bitrate` | `64`, `128`, `192` | MP3 bitrate |
101
+ | `opus_bitrate` | integer | Opus bitrate |
102
+ | `latency` | `"normal"`, `"balanced"` | TTS latency mode |
103
+ | `chunk_length` / `min_chunk_length` | integer | Chunking controls |
104
+ | `temperature`, `top_p`, `repetition_penalty` | number | Sampling controls |
105
+ | `max_new_tokens` | integer | Maximum generated tokens |
106
+ | `normalize` | boolean | Normalize generated audio |
107
+ | `prosody` | object | Prosody tuning |
108
+ | `references` | array | Additional reference objects |
109
+ | `callback_url` | string | Async callback URL |
110
+ | `async` | boolean | Run asynchronously and poll `/fish/tasks` |
77
111
 
78
112
  ## Gotchas
79
113
 
80
- - **TTS (`action:"speech"`) is synchronous** — the response carries `data[0].audio_url`; do NOT poll `/fish/tasks` for it.
81
- - `voice_id` is **required** a bare `{"prompt": "..."}` returns `400 voice_id is required when action is speech`.
82
- - `model` must be `"fish-tts"` for speech (NOT `speech-1.5`); sending a different model returns `400 model is invalid if action is speech`.
83
- - Pricing is based on the **byte count** of the generated audio. Multilingual is automatic.
114
+ - The documented TTS endpoint is `POST /fish/tts` not `/fish/audios`.
115
+ - Choose the Fish engine with the **`model` request header**, not a JSON `model` field.
116
+ - Use `reference_id` from `GET /fish/model` not `voice_id`.
117
+ - Synchronous requests return `audio_url` directly; async jobs should be polled via `/fish/tasks`.
118
+ - The current OpenAPI spec documents voice browsing via `GET /fish/model`; it does **not** document a voice-cloning write endpoint.
@@ -31,6 +31,7 @@ curl -X POST https://api.acedata.cloud/flux/images \
31
31
  |-------|---------|-------|-------|----------|
32
32
  | `flux-dev` | Good | Fast | 256–1440px | Quick generation (default) |
33
33
  | `flux-pro` | High | Medium | 256–1440px | Production work |
34
+ | `flux-2-klein` | Good | Fastest | 256–1440px | Compact / lowest-latency Flux 2 generation |
34
35
  | `flux-2-flex` | High | Fast | 256–1440px | Faster high-quality generation |
35
36
  | `flux-2-pro` | Higher | Medium | 256–1440px | Better prompt following |
36
37
  | `flux-2-max` | Highest | Slow | 256–1440px | Maximum quality generation |
@@ -77,7 +78,8 @@ POST /flux/images
77
78
  - Use pixel dimensions (e.g., `"1024x1024"`) with dev/pro/flux-2 models, aspect ratios (e.g., `"16:9"`) with kontext models
78
79
  - Editing requires kontext models (`flux-kontext-pro` or `flux-kontext-max`) — other models only support generation
79
80
  - `count` parameter generates multiple images in one request (increases cost proportionally)
80
- - `flux-2-max` produces highest quality but is slowestuse dev/flex for iteration and max for final output
81
+ - `flux-2-klein` is the lightest Flux 2 modeluseful when latency matters more than peak quality
82
+ - `flux-2-max` produces highest quality but is slowest — use dev/klein/flex for iteration and max for final output
81
83
  - All generation is async — always set `"callback_url"` to get a task id immediately, then poll `/flux/tasks` using `{"id":"<task_id>"}` or `{"ids":[...],"action":"retrieve_batch"}`
82
84
 
83
85
  > **MCP:** `pip install mcp-flux-pro` | Hosted: `https://flux.mcp.acedata.cloud/mcp` | See [all MCP servers](../_shared/mcp-servers.md)
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: kling-video
3
- description: Generate AI videos with Kuaishou Kling via AceDataCloud API. Use when creating videos from text or images, extending existing videos, applying motion control, or lip-syncing audio/text to video. Supports text-to-video, image-to-video, extend, motion generation, and lip-sync with multiple models and quality modes.
3
+ description: Generate AI videos with Kuaishou Kling via AceDataCloud API. Use when creating videos from text or images, extending existing videos, applying motion control, animating a talking photo from image+audio, or lip-syncing audio/text to video. Supports text-to-video, image-to-video, extend, motion generation, talking-photo, and lip-sync with multiple models and quality modes.
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: acedatacloud
@@ -117,6 +117,21 @@ POST /kling/lip-sync
117
117
  }
118
118
  ```
119
119
 
120
+ ### 6. Talking Photo
121
+
122
+ Animate a still portrait from an image plus an audio track.
123
+
124
+ ```json
125
+ POST /kling/talking-photo
126
+ {
127
+ "image_url": "https://example.com/portrait.jpg",
128
+ "audio_url": "https://example.com/voiceover.mp3",
129
+ "model": "kling-v2-1-master",
130
+ "duration": 5,
131
+ "mode": "pro"
132
+ }
133
+ ```
134
+
120
135
  ## Parameters
121
136
 
122
137
  | Parameter | Values | Description |
@@ -143,6 +158,11 @@ POST /kling/lip-sync
143
158
  | `voice_id` (`/kling/lip-sync`) | string | Voice preset ID used in `text2video` |
144
159
  | `voice_language` (`/kling/lip-sync`) | `"zh"`, `"en"` | TTS language for `text2video` (default `zh`) |
145
160
  | `voice_speed` (`/kling/lip-sync`) | number | TTS speaking speed (default `1.0`) |
161
+ | `image_url` (`/kling/talking-photo`) | URL | Source portrait image |
162
+ | `audio_url` (`/kling/talking-photo`) | URL | Driving audio track |
163
+ | `model` (`/kling/talking-photo`) | `"kling-v1"`, `"kling-v1-6"`, `"kling-v2-master"`, `"kling-v2-1-master"`, `"kling-v2-5-turbo"`, `"kling-v2-6"` | Talking-photo model |
164
+ | `duration` (`/kling/talking-photo`) | `5`, `10` | Talking-photo duration |
165
+ | `mode` (`/kling/talking-photo`) | `"std"`, `"pro"` | Talking-photo quality mode |
146
166
 
147
167
  ## Gotchas
148
168
 
@@ -152,6 +172,7 @@ POST /kling/lip-sync
152
172
  - `end_image_url` is only for `image2video` action — it defines the last frame
153
173
  - Motion control (`/kling/motion`) is a separate endpoint from video generation
154
174
  - Lip-sync is a separate endpoint (`/kling/lip-sync`) and requires `mode`; use `audio_url` for `audio2video` or `text` + voice fields for `text2video`
175
+ - Talking-photo is a separate endpoint (`/kling/talking-photo`) and requires both `image_url` and `audio_url`
155
176
  - `pro` mode costs roughly 2x `std` mode but generates faster with better quality
156
177
  - Task states use `"succeed"` (not "succeeded") — check for this value when polling
157
178
  - `negative_prompt` helps avoid unwanted elements (e.g., "blurry, low quality, text")
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: veo-video
3
- description: Generate AI videos with Google Veo via AceDataCloud API. Use when creating videos from text descriptions, animating still images into video, upscaling/extending videos, re-shooting with new camera motion, or inserting/removing objects. Supports Veo 2, Veo 3, and Veo 3.1 models including fast variants.
3
+ description: Generate AI videos with Google Veo via AceDataCloud API. Use when creating videos from text descriptions, animating still images into video, upscaling/extending videos, re-shooting with new camera motion, or inserting/removing objects. Supports Veo 2 Fast, Veo 3, and Veo 3.1 models including fast and ingredient variants.
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: acedatacloud
@@ -37,7 +37,6 @@ curl -X POST https://api.acedata.cloud/veo/tasks \
37
37
 
38
38
  | Model | Audio | Best For |
39
39
  |-------|-------|----------|
40
- | `veo2` | No | Cost-effective generation |
41
40
  | `veo2-fast` | No | Fast, cost-effective generation (default) |
42
41
  | `veo3` | Yes (native) | Full audiovisual generation |
43
42
  | `veo3-fast` | Yes (native) | Faster audiovisual generation |
@@ -69,7 +68,7 @@ POST /veo/videos
69
68
  "action": "image2video",
70
69
  "prompt": "the scene gently comes to life with wind and subtle motion",
71
70
  "image_urls": ["https://example.com/landscape.jpg"],
72
- "model": "veo2",
71
+ "model": "veo2-fast",
73
72
  "aspect_ratio": "16:9"
74
73
  }
75
74
  ```
@@ -110,7 +109,7 @@ POST /veo/videos
110
109
  | `action` | `"text2video"`, `"image2video"`, `"ingredients2video"`, `"get1080p"` | Generation mode |
111
110
  | `model` | see Models table | Model to use (default: `veo2-fast`) |
112
111
  | `resolution` | `"4k"`, `"1080p"`, `"gif"` | Output resolution (default: 720p) |
113
- | `aspect_ratio` | `"16:9"`, `"9:16"`, `"1:1"`, `"4:3"`, `"3:4"` | Aspect ratio — only valid for `image2video` |
112
+ | `aspect_ratio` | `"16:9"`, `"9:16"` | Aspect ratio — only valid for `image2video` |
114
113
  | `image_urls` | array of strings | Reference image URLs — for `image2video` (up to 2) or `ingredients2video` (up to 3) |
115
114
  | `video_id` | string | Video to upscale — only for `get1080p` |
116
115
  | `translation` | `true` / `false` | Auto-translate prompt to English (default: false) |
@@ -206,11 +205,12 @@ POST /veo/objects
206
205
 
207
206
  ## Gotchas
208
207
 
209
- - Veo 3 and 3.1 models generate **native audio** — `veo2`/`veo2-fast` do NOT support audio
208
+ - Veo 3 and 3.1 models generate **native audio** — `veo2-fast` does NOT support audio
210
209
  - The `get1080p` action uses `video_id` (from a prior generation), not a URL
211
210
  - `aspect_ratio` is **only valid** for the `image2video` action
212
211
  - `image_urls` accepts an array — up to 2 images for `image2video`, up to 3 for `ingredients2video`
213
212
  - `veo31-fast-ingredients` **requires** image input — it cannot do text-only generation
213
+ - Documented `aspect_ratio` values are only `"16:9"` and `"9:16"`
214
214
  - `translation: true` auto-translates Chinese or other non-English prompts before sending to Veo
215
215
  - Task polling uses `id` (not `task_id`) in the `/veo/tasks` request body
216
216
  - Task states use `"succeeded"` (not "completed") — check for this value when polling
@@ -1,18 +1,19 @@
1
1
  ---
2
2
  name: zhihu
3
- description: Read and publish on Zhihu (知乎) with the user's own login cookies (BYOC) — list their published articles with vote/comment stats, inspect one article, and publish a new article. Use when the user mentions 知乎 / Zhihu, "我的知乎文章", reading their article stats (点赞/评论), or publishing/发文 to Zhihu.
3
+ description: Read and publish on Zhihu (知乎) with the user's own login cookies (BYOC) — list published articles & answers with vote/comment stats, inspect an article/answer/question, publish an article, and answer or edit answers to questions. Use when the user mentions 知乎 / Zhihu, "我的知乎文章/回答", reading their stats (点赞/评论), 发文, or 回答/编辑某个问题的回答.
4
4
  when_to_use: |
5
5
  Trigger for anything on the user's Zhihu (知乎) account driven by their own
6
- login cookie: show who they are, list their published articles with
7
- vote-up / comment counts, look at one article's stats, or publish a new
8
- article. This acts as the user's real account, so writes are gated behind
9
- an explicit confirmation.
6
+ login cookie: show who they are, list their published articles or answers
7
+ with vote/comment counts, look at one article / answer / question, publish a
8
+ new article, post a new answer to a question, or edit an existing answer.
9
+ This acts as the user's real account, so writes are gated behind an explicit
10
+ confirmation.
10
11
  connections: [zhihu]
11
12
  allowed_tools: [Bash]
12
13
  license: Apache-2.0
13
14
  metadata:
14
15
  author: acedatacloud
15
- version: "1.1"
16
+ version: "1.2"
16
17
  ---
17
18
 
18
19
  # zhihu — read & publish on Zhihu via your own cookies
@@ -37,6 +38,9 @@ BLOG=$SKILL_DIR/scripts/blog.py
37
38
  python3 $BLOG whoami # who is logged in
38
39
  python3 $BLOG articles --limit 20 # my published articles + stats
39
40
  python3 $BLOG article <article-id> # one article's details + stats
41
+ python3 $BLOG answers --limit 20 # my published answers + stats
42
+ python3 $BLOG answer <answer-id> # one answer's details + stats
43
+ python3 $BLOG question <question-id> # a question's info + whether I answered it
40
44
  ```
41
45
 
42
46
  ## Verify the connection first
@@ -56,11 +60,21 @@ extension). Do **not** retry in a loop.
56
60
  |---|---|
57
61
  | Who am I | `python3 $BLOG whoami` |
58
62
  | My latest articles + vote/comment counts | `python3 $BLOG articles --limit 20` |
59
- | Next page | `python3 $BLOG articles --limit 20 --offset 20` |
63
+ | My latest answers + like/favorite/comment counts | `python3 $BLOG answers --limit 20` |
64
+ | Next page (any list) | add `--offset 20` |
60
65
  | One article's stats | `python3 $BLOG article <id>` |
66
+ | One answer's stats (incl. 赞同 voteup) | `python3 $BLOG answer <id>` |
67
+ | A question's info + my answer id (if any) | `python3 $BLOG question <id>` |
61
68
 
62
- Stats come straight from Zhihu: `voteup_count` (赞同), `comment_count` (评论).
63
- Zhihu does not expose per-article read counts on these endpoints.
69
+ Article stats: `voteup_count` (赞同), `comment_count` (评论). Zhihu does not
70
+ expose per-article read counts on these endpoints.
71
+
72
+ **Answer stat caveat:** the `answers` *list* endpoint does **not** return
73
+ `voteup_count` (赞同) — it only exposes `like_count` (喜欢), `favorite_count`
74
+ (收藏) and `comment_count`. For the authoritative 赞同 count of an answer, call
75
+ `answer <id>` (the single-answer endpoint returns `voteup_count`). `question <id>`
76
+ reports `already_answered` + `my_answer_id` so you know whether to use
77
+ `answer-question` (new) or `edit-answer` (update).
64
78
 
65
79
  ## Publishing — GATED (dry-run unless trailing `--confirm`)
66
80
 
@@ -88,10 +102,46 @@ python3 $BLOG publish --title "标题" --content-file article.html --confirm
88
102
  reports `images_found`. Pass `--no-images` to skip this. So you can hand the
89
103
  CLI HTML/Markdown with normal public image URLs and the pictures survive.
90
104
 
105
+ ## Answering questions — GATED (dry-run unless trailing `--confirm`)
106
+
107
+ Two write commands cover the question/answer side. Both gate exactly like
108
+ `publish`: no trailing `--confirm` → **dry-run**; `--confirm` is honored **only
109
+ as the last argument**. Always show the dry-run, get an explicit "yes", then
110
+ re-run with `--confirm` last.
111
+
112
+ ```sh
113
+ # Content is HTML (same as articles). For Markdown, convert to HTML first.
114
+
115
+ # Post a NEW answer to a question
116
+ python3 $BLOG answer-question --question <qid> --content-file ans.html # dry-run
117
+ python3 $BLOG answer-question --question <qid> --content-file ans.html --draft-only --confirm # PRIVATE draft (safe)
118
+ python3 $BLOG answer-question --question <qid> --content-file ans.html --confirm # PUBLIC, goes live
119
+
120
+ # Edit an EXISTING answer (replaces its live, public content)
121
+ python3 $BLOG edit-answer --id <answer-id> --content-file ans.html # dry-run
122
+ python3 $BLOG edit-answer --id <answer-id> --content-file ans.html --confirm # overwrites live answer
123
+ ```
124
+
125
+ - **One answer per question.** Zhihu allows a single answer per user per
126
+ question. If the user already answered, `answer-question --confirm` returns a
127
+ clear error telling you to use `edit-answer` instead — find the existing answer
128
+ id with `answers` or `question <qid>` (which reports `my_answer_id`).
129
+ - **`--draft-only` is the safe path for new answers** — it saves a *private*
130
+ draft on the question (nothing public). The user reviews it on Zhihu, then you
131
+ re-run without `--draft-only` (with `--confirm`) to publish. Prefer this unless
132
+ the user clearly asked to go live immediately.
133
+ - **`edit-answer` has no private mode** — the answer is already public, so any
134
+ `--confirm` edit is live immediately. It preserves the answer's current repost
135
+ setting unless you override with `--repost allowed|disallowed`.
136
+ - **转载授权** (`--repost allowed|disallowed`): new answers default to
137
+ `disallowed` (don't grant repost rights); editing keeps the current setting.
138
+ - **Images are auto-hosted** for answers too — same behavior and `--no-images`
139
+ flag as `publish`.
140
+
91
141
  ## Gotchas — surface before the user is surprised
92
142
 
93
- - **This is the user's real Zhihu account.** Confirm before any publish; reading
94
- exposes their own private drafts.
143
+ - **This is the user's real Zhihu account.** Confirm before any publish / answer /
144
+ edit; reading exposes their own private drafts.
95
145
  - **Cookie expiry**: Zhihu cookies are short-lived. A `401`/`403` means
96
146
  reconnect at auth.acedata.cloud/user/connections — never loop-retry.
97
147
  - **ToS**: cookie automation is against most platforms' terms. This only ever
@@ -165,6 +165,12 @@ ZH = {
165
165
  "articles": "https://www.zhihu.com/api/v4/members/{token}/articles",
166
166
  "article": "https://www.zhihu.com/api/v4/articles/{id}",
167
167
  "create_draft": "https://zhuanlan.zhihu.com/api/articles/drafts",
168
+ # Answers (回答) — the question/answer side of Zhihu, distinct from articles.
169
+ "member_answers": "https://www.zhihu.com/api/v4/members/{token}/answers",
170
+ "answer": "https://www.zhihu.com/api/v4/answers/{id}",
171
+ "question": "https://www.zhihu.com/api/v4/questions/{id}",
172
+ "question_answers": "https://www.zhihu.com/api/v4/questions/{id}/answers",
173
+ "question_draft": "https://www.zhihu.com/api/v4/questions/{id}/draft",
168
174
  }
169
175
  ZH_FETCH = {"x-requested-with": "fetch"}
170
176
 
@@ -245,6 +251,141 @@ def cmd_article(jar, args):
245
251
  out(res)
246
252
 
247
253
 
254
+ # ── Answers (回答) ───────────────────────────────────────────────────
255
+ #
256
+ # Answers are Zhihu's question/answer side, separate from articles. A user has
257
+ # at most ONE answer per question (a second POST returns RepeatedActionException
258
+ # 103003 — surface that and point at edit-answer). Writes go through the same
259
+ # cookie-only web APIs as articles; no x-zse signature is required.
260
+
261
+ ZH_ANSWER_LIST_INCLUDE = (
262
+ "data[*].comment_count,created_time,updated_time,question"
263
+ )
264
+
265
+
266
+ def _fmt_answer(a: dict) -> dict:
267
+ aid = a.get("id")
268
+ q = a.get("question") or {}
269
+ qid = q.get("id")
270
+ # The member/answers endpoint never returns voteup_count (赞同); it only
271
+ # exposes like_count / favorites under reaction.statistics. The authoritative
272
+ # 赞同 count lives on the single-answer detail endpoint (`answer <id>`).
273
+ react = (a.get("reaction") or {}).get("statistics") or {}
274
+ return {
275
+ "answer_id": str(aid) if aid is not None else None,
276
+ "question_id": str(qid) if qid is not None else None,
277
+ "question_title": q.get("title"),
278
+ "url": (f"https://www.zhihu.com/question/{qid}/answer/{aid}" if (qid and aid) else None),
279
+ "voteup_count": a.get("voteup_count"),
280
+ "like_count": react.get("like_count"),
281
+ "favorite_count": react.get("favorites"),
282
+ "comment_count": a.get("comment_count"),
283
+ "created_time": a.get("created_time"),
284
+ "updated_time": a.get("updated_time"),
285
+ }
286
+
287
+
288
+ def cmd_answers(jar, args):
289
+ me = zh_me(jar)
290
+ token = me.get("url_token")
291
+ if not token:
292
+ die("Zhihu profile has no url_token; cannot list answers.")
293
+ url = ZH["member_answers"].format(token=token)
294
+ q = urllib.parse.urlencode({
295
+ "include": ZH_ANSWER_LIST_INCLUDE,
296
+ "limit": args.limit,
297
+ "offset": args.offset,
298
+ })
299
+ _, data = get_json(f"{url}?{q}", jar, headers=ZH_FETCH)
300
+ items = data.get("data", []) if isinstance(data, dict) else []
301
+ out({
302
+ "total": (data.get("paging") or {}).get("totals") if isinstance(data, dict) else None,
303
+ "count": len(items),
304
+ "answers": [_fmt_answer(a) for a in items],
305
+ })
306
+
307
+
308
+ def cmd_answer(jar, args):
309
+ base = ZH["answer"].format(id=args.id)
310
+ q = urllib.parse.urlencode({
311
+ "include": "content,voteup_count,comment_count,created_time,updated_time,question",
312
+ })
313
+ _, a = get_json(f"{base}?{q}", jar, headers=ZH_FETCH)
314
+ if not isinstance(a, dict) or not a.get("id"):
315
+ die(f"answer {args.id} not found or not accessible: {str(a)[:300]}")
316
+ res = _fmt_answer(a)
317
+ res["content_excerpt"] = (a.get("excerpt") or "")[:200]
318
+ out(res)
319
+
320
+
321
+ def cmd_question(jar, args):
322
+ base = ZH["question"].format(id=args.id)
323
+ q = urllib.parse.urlencode({
324
+ "include": "answer_count,follower_count,visit_count,comment_count,detail",
325
+ })
326
+ _, qd = get_json(f"{base}?{q}", jar, headers=ZH_FETCH)
327
+ if not isinstance(qd, dict) or not (qd.get("id") or qd.get("title")):
328
+ die(f"question {args.id} not found or not accessible: {str(qd)[:300]}")
329
+ # Detect whether the logged-in user already answered this question so the
330
+ # caller knows to use `edit-answer` instead of `answer-question`.
331
+ mine = _my_answer_for_question(jar, args.id)
332
+ out({
333
+ "question_id": str(qd.get("id") or args.id),
334
+ "title": qd.get("title"),
335
+ "url": f"https://www.zhihu.com/question/{args.id}",
336
+ "answer_count": qd.get("answer_count"),
337
+ "follower_count": qd.get("follower_count"),
338
+ "visit_count": qd.get("visit_count"),
339
+ "detail_excerpt": _strip_tags(qd.get("detail") or "")[:300],
340
+ "my_answer_id": mine,
341
+ "already_answered": bool(mine),
342
+ })
343
+
344
+
345
+ _TAG_RE = re.compile(r"<[^>]+>")
346
+
347
+
348
+ def _strip_tags(html: str) -> str:
349
+ return _TAG_RE.sub("", html or "").strip()
350
+
351
+
352
+ def _my_answer_for_question(jar, question_id: str):
353
+ """Return the logged-in user's answer id for a question, or None.
354
+
355
+ Scans the *user's own* answers (bounded by their answer count) and matches
356
+ on question id. This is reliable even for popular questions — unlike walking
357
+ the question's own answer list, which may have thousands of entries. For an
358
+ account with more answers than the scan cap this is best-effort.
359
+ """
360
+ me = zh_me(jar)
361
+ token = me.get("url_token")
362
+ if not token:
363
+ return None
364
+ url = ZH["member_answers"].format(token=token)
365
+ qid = str(question_id)
366
+ offset = 0
367
+ for _ in range(15): # up to 300 of the user's own answers
368
+ q = urllib.parse.urlencode({
369
+ "include": "data[*].question",
370
+ "limit": 20,
371
+ "offset": offset,
372
+ })
373
+ status, data = request("GET", f"{url}?{q}", jar, headers=ZH_FETCH)
374
+ try:
375
+ data = json.loads(data)
376
+ except json.JSONDecodeError:
377
+ return None
378
+ items = data.get("data", []) if isinstance(data, dict) else []
379
+ for a in items:
380
+ if str((a.get("question") or {}).get("id")) == qid:
381
+ return str(a.get("id"))
382
+ if (data.get("paging") or {}).get("is_end", True) or not items:
383
+ return None
384
+ offset += 20
385
+ return None
386
+
387
+
388
+
248
389
  # ── Image re-hosting ────────────────────────────────────────
249
390
  #
250
391
  # Zhihu silently drops any <img> whose src is not on its own CDN, so external
@@ -539,11 +680,187 @@ def cmd_publish(jar, args):
539
680
  })
540
681
 
541
682
 
683
+ def _read_content(args) -> str:
684
+ content = args.content
685
+ if args.content_file:
686
+ try:
687
+ with open(args.content_file, encoding="utf-8") as f:
688
+ content = f.read()
689
+ except OSError as e:
690
+ die(f"cannot read --content-file: {e}")
691
+ if content is None:
692
+ die("provide --content-file <path> or --content <html>")
693
+ return content
694
+
695
+
696
+ def _reshipment(value):
697
+ # Zhihu accepts "allowed" / "disallowed" for 转载授权 (repost permission).
698
+ return value if value in ("allowed", "disallowed") else None
699
+
700
+
701
+ def cmd_answer_question(jar, args):
702
+ """Post a NEW answer to a question (GATED). --draft-only saves a private draft."""
703
+ qid = args.question
704
+ if not qid:
705
+ die("--question <question-id> is required")
706
+ content = _read_content(args)
707
+ # Fetch the question title so the dry-run shows what is being answered.
708
+ title = None
709
+ try:
710
+ _, qd = get_json(
711
+ f"{ZH['question'].format(id=qid)}?{urllib.parse.urlencode({'include': 'title'})}",
712
+ jar, headers=ZH_FETCH,
713
+ )
714
+ title = qd.get("title") if isinstance(qd, dict) else None
715
+ except SystemExit:
716
+ raise
717
+ except Exception:
718
+ pass
719
+
720
+ reship = _reshipment(args.repost) or "disallowed"
721
+
722
+ if not CONFIRM:
723
+ out({
724
+ "dry_run": True,
725
+ "command": "answer-question",
726
+ "platform": "zhihu",
727
+ "question_id": str(qid),
728
+ "question_title": title,
729
+ "draft_only": args.draft_only,
730
+ "reshipment_settings": reship,
731
+ "content_bytes": len(content),
732
+ "images_found": count_images(content),
733
+ "note": "re-run with --confirm as the LAST argument to actually write. "
734
+ "Without --draft-only this publishes a PUBLIC answer on the user's real "
735
+ "account. One answer per question — if you already answered, use edit-answer.",
736
+ })
737
+ return
738
+
739
+ image_stats = {"found": 0, "rehosted": 0, "failed": 0}
740
+ if not args.no_images:
741
+ content, image_stats = rehost_images(jar, content)
742
+
743
+ if args.draft_only:
744
+ # Private autosave draft on the question — nothing goes public.
745
+ status, text = request(
746
+ "PUT", ZH["question_draft"].format(id=qid), jar,
747
+ headers=ZH_FETCH, body={"content": content, "delta_time": 5},
748
+ )
749
+ if status >= 400:
750
+ die(f"save-draft failed ({status}) for question {qid}: {text[:300]}")
751
+ out({
752
+ "ok": True,
753
+ "draft_only": True,
754
+ "question_id": str(qid),
755
+ "images": image_stats,
756
+ "review_url": f"https://www.zhihu.com/question/{qid}",
757
+ "note": "Private draft saved. Open the question to review, then re-run "
758
+ "without --draft-only (and --confirm) to publish.",
759
+ })
760
+ return
761
+
762
+ status, text = request(
763
+ "POST", ZH["question_answers"].format(id=qid), jar,
764
+ headers=ZH_FETCH, body={"content": content, "reshipment_settings": reship},
765
+ )
766
+ try:
767
+ res = json.loads(text)
768
+ except json.JSONDecodeError:
769
+ res = {}
770
+ if status >= 400:
771
+ # Zhihu's `error` is usually a dict {code, name, message} but can be a
772
+ # bare string; guard both. `code` may arrive as int or str.
773
+ err = res.get("error") if isinstance(res, dict) and isinstance(res.get("error"), dict) else {}
774
+ if str(err.get("code")) == "103003":
775
+ die(
776
+ f"you already answered question {qid}; Zhihu allows one answer per "
777
+ f"question. Find your answer id with `answers` and use "
778
+ f"`edit-answer --id <answer-id>` instead."
779
+ )
780
+ die(f"publish answer failed ({status}) for question {qid}: {text[:300]}")
781
+ aid = res.get("id") if isinstance(res, dict) else None
782
+ if not aid:
783
+ die(f"publish answer returned no id ({status}): {text[:300]}")
784
+ out({
785
+ "ok": True,
786
+ "published": True,
787
+ "question_id": str(qid),
788
+ "answer_id": str(aid),
789
+ "images": image_stats,
790
+ "url": f"https://www.zhihu.com/question/{qid}/answer/{aid}",
791
+ })
792
+
793
+
794
+ def cmd_edit_answer(jar, args):
795
+ """Edit an EXISTING answer's content (GATED). The answer stays public."""
796
+ aid = args.id
797
+ if not aid:
798
+ die("--id <answer-id> is required")
799
+ content = _read_content(args)
800
+ # Read the current answer to preserve its repost setting and show context.
801
+ cur = {}
802
+ try:
803
+ _, cur = get_json(
804
+ f"{ZH['answer'].format(id=aid)}?{urllib.parse.urlencode({'include': 'reshipment_settings,question'})}",
805
+ jar, headers=ZH_FETCH,
806
+ )
807
+ except SystemExit:
808
+ raise
809
+ except Exception:
810
+ cur = {}
811
+ if not isinstance(cur, dict):
812
+ cur = {}
813
+ # Keep the answer's current repost setting; if it couldn't be read and the
814
+ # user gave no override, fall back to the conservative "disallowed" rather
815
+ # than silently granting repost rights.
816
+ reship = _reshipment(args.repost) or cur.get("reshipment_settings") or "disallowed"
817
+ q = cur.get("question") or {}
818
+
819
+ if not CONFIRM:
820
+ out({
821
+ "dry_run": True,
822
+ "command": "edit-answer",
823
+ "platform": "zhihu",
824
+ "answer_id": str(aid),
825
+ "question_title": q.get("title"),
826
+ "reshipment_settings": reship,
827
+ "content_bytes": len(content),
828
+ "images_found": count_images(content),
829
+ "note": "re-run with --confirm as the LAST argument to actually overwrite. "
830
+ "This replaces the live, public answer's content on the user's real account.",
831
+ })
832
+ return
833
+
834
+ image_stats = {"found": 0, "rehosted": 0, "failed": 0}
835
+ if not args.no_images:
836
+ content, image_stats = rehost_images(jar, content)
837
+
838
+ status, text = request(
839
+ "PUT", ZH["answer"].format(id=aid), jar,
840
+ headers=ZH_FETCH, body={"content": content, "reshipment_settings": reship},
841
+ )
842
+ if status >= 400:
843
+ die(f"edit answer failed ({status}) for {aid}: {text[:300]}")
844
+ qid = q.get("id")
845
+ out({
846
+ "ok": True,
847
+ "edited": True,
848
+ "answer_id": str(aid),
849
+ "images": image_stats,
850
+ "url": (f"https://www.zhihu.com/question/{qid}/answer/{aid}" if qid else None),
851
+ })
852
+
853
+
542
854
  COMMANDS = {
543
855
  "whoami": cmd_whoami,
544
856
  "articles": cmd_articles,
545
857
  "article": cmd_article,
546
858
  "publish": cmd_publish,
859
+ "answers": cmd_answers,
860
+ "answer": cmd_answer,
861
+ "question": cmd_question,
862
+ "answer-question": cmd_answer_question,
863
+ "edit-answer": cmd_edit_answer,
547
864
  }
548
865
 
549
866
 
@@ -571,6 +888,38 @@ def main() -> None:
571
888
  sp.add_argument("--no-images", action="store_true",
572
889
  help="skip re-hosting external images to Zhihu's CDN")
573
890
 
891
+ sp = sub.add_parser("answers", help="list the user's published answers + stats")
892
+ sp.add_argument("--limit", type=int, default=20)
893
+ sp.add_argument("--offset", type=int, default=0)
894
+
895
+ sp = sub.add_parser("answer", help="one answer's details + stats")
896
+ sp.add_argument("id")
897
+
898
+ sp = sub.add_parser("question", help="a question's info + whether you already answered it")
899
+ sp.add_argument("id")
900
+
901
+ sp = sub.add_parser("answer-question",
902
+ help="post a NEW answer to a question (GATED by trailing --confirm)")
903
+ sp.add_argument("--question", help="question id to answer")
904
+ sp.add_argument("--content", help="HTML content inline")
905
+ sp.add_argument("--content-file", help="path to an HTML file")
906
+ sp.add_argument("--draft-only", action="store_true",
907
+ help="save a private draft on the question; do NOT go public")
908
+ sp.add_argument("--repost", choices=["allowed", "disallowed"],
909
+ help="转载授权: allow or disallow reposting (default disallowed)")
910
+ sp.add_argument("--no-images", action="store_true",
911
+ help="skip re-hosting external images to Zhihu's CDN")
912
+
913
+ sp = sub.add_parser("edit-answer",
914
+ help="overwrite an existing answer's content (GATED by trailing --confirm)")
915
+ sp.add_argument("--id", help="answer id to edit")
916
+ sp.add_argument("--content", help="HTML content inline")
917
+ sp.add_argument("--content-file", help="path to an HTML file")
918
+ sp.add_argument("--repost", choices=["allowed", "disallowed"],
919
+ help="转载授权: override repost permission (default keeps current)")
920
+ sp.add_argument("--no-images", action="store_true",
921
+ help="skip re-hosting external images to Zhihu's CDN")
922
+
574
923
  args = p.parse_args(ARGV)
575
924
  jar = load_cookies(args.platform)
576
925
  COMMANDS[args.command](jar, args)