cazyundee commited on
Commit
7dcbaae
Β·
verified Β·
1 Parent(s): 01cbdc2

Add full API reference for chat agent integration

Browse files
Files changed (1) hide show
  1. API_REFERENCE.md +248 -0
API_REFERENCE.md ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Respite API Reference
2
+
3
+ **Base URL:** `https://cazyundee-respite-api.hf.space`
4
+
5
+ **Version:** 1.0.0
6
+ **Authentication:** None required
7
+ **Content Types:** `application/json`, `audio/wav`
8
+
9
+ ---
10
+
11
+ ## Overview
12
+
13
+ Respite is a general-purpose AI API running on Hugging Face ZeroGPU infrastructure. It currently exposes two capabilities: **web search** (DuckDuckGo, no API key) and **audio generation** (Stable Audio 3 Small). The API is self-describing β€” call the discovery endpoints to enumerate capabilities and server specs at runtime.
14
+
15
+ ---
16
+
17
+ ## Endpoints
18
+
19
+ ### `GET /respite/specs`
20
+
21
+ Returns server metadata, hardware specs, and runtime limits.
22
+
23
+ **Response:**
24
+
25
+ ```json
26
+ {
27
+ "name": "Respite API",
28
+ "version": "1.0.0",
29
+ "description": "General-purpose AI API server with audio generation capabilities.",
30
+ "base_path": "/respite",
31
+ "authentication": "none",
32
+ "content_types": ["application/json", "audio/wav"],
33
+ "resources_endpoint": "/respite/resources",
34
+ "specs_endpoint": "/respite/specs",
35
+ "limits": {
36
+ "max_concurrent_requests": 1,
37
+ "max_queue_size": 4,
38
+ "audio_max_duration_seconds": 120
39
+ },
40
+ "runtime": {
41
+ "platform": "Linux-6.12.94-123.192.amzn2023.x86_64-x86_64-with-glibc2.36",
42
+ "python_version": "3.10.13",
43
+ "cpu_cores": 16,
44
+ "host_cpu_cores": 192,
45
+ "ram_bytes": 104000000000,
46
+ "storage_total_bytes": 8589854879744,
47
+ "storage_used_bytes": 6852819365888,
48
+ "storage_free_bytes": 1737035513856,
49
+ "hardware": "zero-a10g",
50
+ "gpu": {
51
+ "type": "NVIDIA RTX Pro 6000 Blackwell",
52
+ "vram_bytes": 51539607552,
53
+ "shared_zero_gpu": true
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ **Fields:**
60
+
61
+ | Field | Description |
62
+ |---|---|
63
+ | `limits.max_concurrent_requests` | Only 1 request can be processed at a time (ZeroGPU queue) |
64
+ | `limits.max_queue_size` | Max 4 requests queued; beyond that, 503 |
65
+ | `limits.audio_max_duration_seconds` | Max audio length per generation |
66
+ | `runtime.gpu.shared_zero_gpu` | GPU time is shared β€” requests are queued and batched |
67
+ | `runtime.ram_bytes` | Container memory limit (not host total) |
68
+ | `runtime.cpu_cores` | Container CPU limit (not host total) |
69
+
70
+ ---
71
+
72
+ ### `GET /respite/resources`
73
+
74
+ Lists all callable capabilities.
75
+
76
+ **Response:**
77
+
78
+ ```json
79
+ {
80
+ "resources": {
81
+ "audio_generation": {
82
+ "name": "Audio generation",
83
+ "description": "Generate music or sound effects from a text prompt.",
84
+ "endpoint": "/respite/audio/generate",
85
+ "method": "POST",
86
+ "input": {
87
+ "prompt": "string",
88
+ "duration": "number (1-120 seconds)",
89
+ "steps": "integer (1-50)",
90
+ "cfg_scale": "number (0-10)",
91
+ "seed": "integer (-1 for random)",
92
+ "model": "small-music | small-sfx"
93
+ },
94
+ "output": "WAV audio file"
95
+ },
96
+ "web_search": {
97
+ "name": "Web search",
98
+ "description": "Search the web via DuckDuckGo. No API key required.",
99
+ "endpoint": "/respite/search",
100
+ "method": "GET",
101
+ "input": {
102
+ "q": "string (search query)",
103
+ "max_results": "integer (1-50, default 10)"
104
+ },
105
+ "output": "JSON with title, url, content per result"
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ ---
112
+
113
+ ### `GET /respite/search`
114
+
115
+ Search the web via DuckDuckGo. No API key required.
116
+
117
+ **Query Parameters:**
118
+
119
+ | Parameter | Type | Required | Default | Description |
120
+ |---|---|---|---|---|
121
+ | `q` | string | Yes | β€” | Search query |
122
+ | `max_results` | integer | No | 10 | Number of results (1-50) |
123
+
124
+ **Request:**
125
+
126
+ ```
127
+ GET /respite/search?q=what+is+python&max_results=3
128
+ ```
129
+
130
+ **Response:**
131
+
132
+ ```json
133
+ {
134
+ "query": "what is python",
135
+ "results": [
136
+ {
137
+ "title": "Python (programming language) - Wikipedia",
138
+ "url": "https://en.wikipedia.org/wiki/Python_(programming_language)",
139
+ "content": "Python is a high-level, general-purpose programming language that emphasizes code readability..."
140
+ },
141
+ {
142
+ "title": "What is Python? Executive Summary | Python.org",
143
+ "url": "https://www.python.org/doc/essays/blurb/",
144
+ "content": "Python is a high-level, object-oriented, interpreted language..."
145
+ }
146
+ ],
147
+ "total_results": 2
148
+ }
149
+ ```
150
+
151
+ **Error responses:**
152
+
153
+ | Status | Body | Cause |
154
+ |---|---|---|
155
+ | 400 | `{"error": "Missing query parameter 'q'"}` | No query provided |
156
+ | 502 | `{"error": "..."}` | Search backend unreachable |
157
+
158
+ ---
159
+
160
+ ### `POST /respite/audio/generate`
161
+
162
+ Generate music or sound effects from a text prompt using Stable Audio 3.
163
+
164
+ **Request body (JSON):**
165
+
166
+ | Field | Type | Required | Default | Description |
167
+ |---|---|---|---|---|
168
+ | `prompt` | string | Yes | β€” | Text description of desired audio |
169
+ | `duration` | number | No | 30 | Duration in seconds (1-120) |
170
+ | `steps` | integer | No | 8 | Inference steps (1-50). Higher = better quality, slower |
171
+ | `cfg_scale` | number | No | 1.0 | Classifier-free guidance scale (0-10). Higher = more prompt adherence |
172
+ | `seed` | integer | No | -1 | Random seed. -1 = random each time |
173
+ | `model` | string | No | "small-music" | Either `"small-music"` or `"small-sfx"` |
174
+
175
+ **Request:**
176
+
177
+ ```bash
178
+ curl -X POST "https://cazyundee-respite-api.hf.space/respite/audio/generate" \
179
+ -H "Content-Type: application/json" \
180
+ -d '{"prompt": "upbeat synthwave melody", "duration": 30, "model": "small-music"}'
181
+ ```
182
+
183
+ **Response:**
184
+
185
+ - **Content-Type:** `audio/wav`
186
+ - **Body:** Raw WAV audio binary (44100 Hz sample rate)
187
+ - The response is a downloadable audio file, not JSON
188
+
189
+ **Error responses:**
190
+
191
+ | Status | Body | Cause |
192
+ |---|---|---|
193
+ | 503 | `{"detail":"Queue is full. Please try again later."}` | All 4 queue slots occupied |
194
+ | 500 | Server error | Generation failed |
195
+
196
+ **Important notes:**
197
+
198
+ - ZeroGPU shares one GPU across all requests. The server processes requests serially.
199
+ - First request triggers model loading (~30-60s). Subsequent requests use the cached model.
200
+ - The `model` field selects between `"small-music"` (general music) and `"small-sfx"` (sound effects).
201
+ - The returned audio is always WAV format, 44100 Hz sample rate, 16-bit PCM.
202
+
203
+ ---
204
+
205
+ ## Rate Limits
206
+
207
+ - **Max concurrent requests:** 1 (GPU locked)
208
+ - **Max queue size:** 4 (503 if full)
209
+ - **Audio generation:** ~5-15s per request after model is loaded (varies by `steps` and `duration`)
210
+ - **Search:** No limit (DuckDuckGo backend, no API key)
211
+
212
+ ---
213
+
214
+ ## Error Handling
215
+
216
+ All errors return JSON with an `"error"` or `"detail"` field:
217
+
218
+ ```json
219
+ {"error": "Missing query parameter 'q'"}
220
+ {"detail": "Queue is full. Please try again later."}
221
+ ```
222
+
223
+ Check the HTTP status code:
224
+
225
+ | Code | Meaning |
226
+ |---|---|
227
+ | 200 | Success |
228
+ | 400 | Bad request (missing/invalid parameters) |
229
+ | 502 | Upstream service unreachable |
230
+ | 503 | Queue full, try again |
231
+
232
+ ---
233
+
234
+ ## Integration Notes for Chat Agents
235
+
236
+ 1. **Discover capabilities at runtime** β€” Call `GET /respite/resources` to enumerate what the API can do. Do not hardcode resource names.
237
+
238
+ 2. **Search first, generate second** β€” For user queries about current events or facts, use `/respite/search` before falling back to knowledge. Search is fast and free.
239
+
240
+ 3. **Audio generation is queued** β€” Only 1 generation runs at a time. If the queue is full (503), retry with exponential backoff. Do not retry rapidly.
241
+
242
+ 4. **Model selection** β€” Use `"small-music"` for music, melodies, ambient sound. Use `"small-sfx"` for sound effects, foley, short percussive sounds.
243
+
244
+ 5. **Response handling** β€” `/respite/audio/generate` returns binary WAV, not JSON. Save to a `.wav` file and play/serve it. Do not try to JSON-parse the response body.
245
+
246
+ 6. **Specs for capability planning** β€” `GET /respite/specs` tells you GPU type, VRAM, and queue limits. Use this to decide what to offer users (e.g., don't promise 4-minute tracks β€” max is 120s).
247
+
248
+ 7. **Graceful degradation** β€” If the API is down (503, 502), tell the user the service is temporarily unavailable rather than hanging. ZeroGPU Spaces can go cold when idle.