suno 0.8.0

Generate AI music from your terminal — Suno v5.5 with tags, exclude, vocal control, and all generation features
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
use serde::{Deserialize, Serialize};

// --- Billing / Account ---

/// Only `total_credits_left` and `plan` are load-bearing (auth verify,
/// credits display). Everything else defaults so one renamed/removed field
/// in Suno's billing response doesn't break credits+models+auth at once.
#[derive(Debug, Deserialize, Serialize)]
pub struct BillingInfo {
    #[serde(default)]
    pub credits: u64,
    pub total_credits_left: u64,
    #[serde(default)]
    pub monthly_usage: u64,
    #[serde(default)]
    pub monthly_limit: u64,
    #[serde(default)]
    pub is_active: bool,
    pub plan: Plan,
    #[serde(default)]
    pub models: Vec<Model>,
    #[serde(default)]
    pub period: String,
    #[serde(default)]
    pub renews_on: Option<String>,
    #[serde(default)]
    pub remaster_model_types: Vec<RemasterModelInfo>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Plan {
    pub name: String,
    #[serde(default)]
    pub plan_key: String,
    #[serde(default)]
    pub usage_plan_features: Vec<Feature>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Feature {
    pub name: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Model {
    pub name: String,
    pub external_key: String,
    #[serde(default)]
    pub can_use: bool,
    #[serde(default)]
    pub is_default_model: bool,
    #[serde(default)]
    pub description: String,
    #[serde(default)]
    pub max_lengths: MaxLengths,
}

#[derive(Debug, Deserialize, Serialize, Default)]
pub struct MaxLengths {
    #[serde(default)]
    pub title: u32,
    #[serde(default)]
    pub prompt: u32,
    #[serde(default)]
    pub tags: u32,
    #[serde(default)]
    pub negative_tags: u32,
    #[serde(default)]
    pub gpt_description_prompt: u32,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct RemasterModelInfo {
    pub name: String,
    pub external_key: String,
    pub is_default_model: bool,
    /// Suno's billing/info response for remaster models does NOT include this
    /// field — keep it optional so deserialization succeeds.
    #[serde(default)]
    pub can_use: bool,
}

// --- Clips / Feed ---

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Clip {
    pub id: String,
    pub title: String,
    pub status: String,
    pub model_name: String,
    pub audio_url: Option<String>,
    pub video_url: Option<String>,
    pub image_url: Option<String>,
    pub created_at: String,
    #[serde(default)]
    pub play_count: u64,
    #[serde(default)]
    pub upvote_count: u64,
    #[serde(default)]
    pub metadata: ClipMetadata,
}

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct ClipMetadata {
    pub tags: Option<String>,
    pub prompt: Option<String>,
    pub duration: Option<f64>,
    pub avg_bpm: Option<f64>,
    #[serde(default)]
    pub has_stem: bool,
    #[serde(default)]
    pub is_remix: bool,
    #[serde(default)]
    pub make_instrumental: bool,
    #[serde(rename = "type")]
    pub clip_type: Option<String>,
    /// Set by Suno when a clip lands in `status == "error"` (moderation,
    /// internal failure). Skipped on output so healthy clips keep their shape.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_message: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct FeedResponse {
    #[serde(default)]
    pub clips: Vec<Clip>,
    /// Opaque pagination token — pass back via `list --cursor`.
    pub next_cursor: Option<String>,
    #[serde(default)]
    pub has_more: bool,
}

// --- Feed V3 Request ---

#[derive(Debug, Serialize)]
pub struct FeedV3Request {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<FeedFilters>,
}

#[derive(Debug, Serialize)]
pub struct FeedFilters {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "searchText")]
    pub search_text: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trashed: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "fullSong")]
    pub full_song: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stem: Option<FilterPresence>,
}

#[derive(Debug, Serialize)]
pub struct FilterPresence {
    pub presence: String,
}

// --- Generation ---
//
// Schema captured from a real Suno web-app POST to `/api/generate/v2-web/`
// on 2026-04-07 (see API_INTELLIGENCE.md). The old `/api/generate/v2/` path
// returns `Token validation failed` since Suno started routing creates
// through `v2-web` exclusively. Most of the new `null` fields are pure
// placeholders the web app sends regardless of mode — they MUST be present
// or pydantic returns `missing field`.

#[derive(Debug, Serialize)]
pub struct GenerateRequest {
    /// Captcha/anti-bot token. Only needed when `/api/c/check` says the
    /// account is captcha-gated; `null` otherwise (matches the web app).
    /// No companion `token_provider` field: Suno's v2-web schema types it as
    /// an integer and 422s on a string, and the hCaptcha flow works without it.
    pub token: Option<String>,
    pub generation_type: String,
    pub title: Option<String>,
    pub tags: Option<String>,
    /// Always present, defaults to "" (empty string, NOT null).
    pub negative_tags: String,
    pub mv: String,
    pub prompt: String,
    pub make_instrumental: bool,
    pub user_uploaded_images_b64: Option<String>,
    pub metadata: GenerateMetadata,
    /// Always present, empty array unless overriding model fields.
    pub override_fields: Vec<serde_json::Value>,
    pub cover_clip_id: Option<String>,
    pub cover_start_s: Option<f64>,
    pub cover_end_s: Option<f64>,
    pub persona_id: Option<String>,
    pub artist_clip_id: Option<String>,
    pub artist_start_s: Option<f64>,
    pub artist_end_s: Option<f64>,
    pub continue_clip_id: Option<String>,
    pub continued_aligned_prompt: Option<String>,
    pub continue_at: Option<f64>,
    /// Random UUID generated per request — required.
    pub transaction_uuid: String,
}

impl GenerateRequest {
    /// Build a `GenerateRequest` with all the new-schema placeholder fields
    /// pre-populated (nulls, empty arrays, fresh UUIDs). Callers only need to
    /// override the fields that matter for their command.
    pub fn new(mv: &str, create_mode: &str) -> Self {
        Self {
            token: None,
            generation_type: "TEXT".to_string(),
            title: None,
            tags: None,
            negative_tags: String::new(),
            mv: mv.to_string(),
            prompt: String::new(),
            make_instrumental: false,
            user_uploaded_images_b64: None,
            metadata: GenerateMetadata::new(create_mode),
            override_fields: Vec::new(),
            cover_clip_id: None,
            cover_start_s: None,
            cover_end_s: None,
            persona_id: None,
            artist_clip_id: None,
            artist_start_s: None,
            artist_end_s: None,
            continue_clip_id: None,
            continued_aligned_prompt: None,
            continue_at: None,
            transaction_uuid: uuid::Uuid::new_v4().to_string(),
        }
    }
}

/// Web-app metadata block. All fields are required by the new schema even if
/// they're decorative. `user_tier` is NOT validated server-side (verified with
/// empty string and arbitrary text — both succeed).
#[derive(Debug, Serialize)]
pub struct GenerateMetadata {
    pub web_client_pathname: String,
    pub is_max_mode: bool,
    pub is_mumble: bool,
    pub create_mode: String,
    pub user_tier: String,
    /// Random UUID generated per request — looks decorative but must be present.
    pub create_session_token: String,
    pub disable_volume_normalization: bool,
    /// Control sliders (weirdness / style influence). Optional — only sent
    /// when --weirdness or --style-influence is passed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub control_sliders: Option<ControlSliders>,
}

impl GenerateMetadata {
    /// Build a metadata block with default web-app values + a fresh session
    /// token. This matches what the real Suno UI sends per generation.
    pub fn new(create_mode: &str) -> Self {
        Self {
            web_client_pathname: "/create".to_string(),
            is_max_mode: false,
            is_mumble: false,
            create_mode: create_mode.to_string(),
            user_tier: String::new(),
            create_session_token: uuid::Uuid::new_v4().to_string(),
            disable_volume_normalization: false,
            control_sliders: None,
        }
    }
}

#[derive(Debug, Serialize)]
pub struct ControlSliders {
    /// Weirdness: 0.0-1.0 (maps from 0-100 in UI)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weirdness_constraint: Option<f64>,
    /// Style weight: 0.0-1.0 (maps from 0-100 in UI)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub style_weight: Option<f64>,
    /// Audio influence: 0.0-1.0 (maps from 0-100 in UI) — how strongly the
    /// source audio shapes covers/remixes. Field name confirmed in the wild.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub audio_weight: Option<f64>,
}

#[derive(Debug, Deserialize)]
pub struct GenerateResponse {
    #[serde(default)]
    pub clips: Vec<Clip>,
    /// Top-level submission status. Suno can return HTTP 200 with
    /// `{"status":"error","clips":[]}` when a create is rejected server-side;
    /// generate() must treat that as a failure, not silent success.
    #[serde(default)]
    pub status: Option<String>,
}

// --- Lyrics ---

#[derive(Debug, Deserialize)]
pub struct LyricsSubmitResponse {
    pub id: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct LyricsResult {
    pub text: String,
    pub title: String,
    pub status: String,
    #[serde(default)]
    pub error_message: String,
    #[serde(default)]
    pub tags: Vec<String>,
}

// --- Aligned / Timed Lyrics ---

#[derive(Debug, Deserialize, Serialize)]
pub struct AlignedWord {
    pub word: String,
    pub start_s: f64,
    pub end_s: f64,
    #[serde(default)]
    pub success: bool,
    #[serde(default)]
    pub p_align: Option<f64>,
}

// --- Captcha Check ---

/// `POST /api/c/check` with `{"ctype":"generation"}` — verified live
/// 2026-07-18: `{"required": false, "captcha_version": 1}` for accounts
/// above Suno's trust threshold.
#[derive(Debug, Deserialize)]
pub struct CaptchaCheckResponse {
    // No serde default: a payload missing `required` must fail to parse so the
    // caller's error branch treats captcha as required (fail closed) rather
    // than silently reading a defaulted `false` and skipping the solver.
    pub required: bool,
    #[serde(default)]
    pub captcha_version: Option<i64>,
}

// --- Set Metadata ---

#[derive(Debug, Serialize)]
pub struct SetMetadataRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lyrics: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub caption: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove_image_cover: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove_video_cover: Option<bool>,
}

// --- Set Visibility ---

#[derive(Debug, Serialize)]
pub struct SetVisibilityRequest {
    pub is_public: bool,
}

// --- Concat ---

#[derive(Debug, Serialize)]
pub struct ConcatRequest {
    pub clip_id: String,
}

// --- Persona ---

#[derive(Debug, Deserialize, Serialize)]
pub struct PersonaResponse {
    pub persona: PersonaInfo,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct PersonaInfo {
    pub id: String,
    pub name: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub image_s3_id: Option<String>,
    #[serde(default)]
    pub user_display_name: Option<String>,
    #[serde(default)]
    pub user_handle: Option<String>,
    #[serde(default)]
    pub persona_clips: Vec<serde_json::Value>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn generate_request_token_serialization() {
        let mut req = GenerateRequest::new("chirp-fenix", "custom");
        let v = serde_json::to_value(&req).unwrap();
        // token is null when no captcha is required (the common case); there
        // is no token_provider field — Suno's v2-web schema rejects it.
        assert_eq!(v["token"], serde_json::Value::Null);
        assert!(v.get("token_provider").is_none());

        req.token = Some("solved".into());
        let v = serde_json::to_value(&req).unwrap();
        assert_eq!(v["token"], "solved");
    }

    #[test]
    fn feed_request_cursor_plumbing() {
        // feed/v3 wants an opaque cursor token, omitted entirely on page one.
        let req = FeedV3Request {
            cursor: Some("opaque-token".into()),
            limit: Some(20),
            filters: None,
        };
        let v = serde_json::to_value(&req).unwrap();
        assert_eq!(v["cursor"], "opaque-token");

        let req = FeedV3Request {
            cursor: None,
            limit: None,
            filters: None,
        };
        let v = serde_json::to_value(&req).unwrap();
        assert!(v.get("cursor").is_none());
    }

    #[test]
    fn captcha_check_response_parses_required_field() {
        // Live shape verified 2026-07-18. The old struct expected a
        // `captcha_required` field that the API never sends.
        let r: CaptchaCheckResponse =
            serde_json::from_str(r#"{"required": false, "captcha_version": 1}"#).unwrap();
        assert!(!r.required);
        assert_eq!(r.captcha_version, Some(1));

        let r: CaptchaCheckResponse = serde_json::from_str(r#"{"required": true}"#).unwrap();
        assert!(r.required);
        assert_eq!(r.captcha_version, None);

        // A payload without `required` must NOT parse: the solver-fallback path
        // depends on this failing so a missing field reads as "captcha required"
        // instead of a defaulted false.
        assert!(serde_json::from_str::<CaptchaCheckResponse>(r#"{"captcha_version": 1}"#).is_err());
    }

    #[test]
    fn control_sliders_serialize_audio_weight() {
        let s = ControlSliders {
            weirdness_constraint: None,
            style_weight: None,
            audio_weight: Some(0.65),
        };
        let v = serde_json::to_value(&s).unwrap();
        assert_eq!(v["audio_weight"], 0.65);
        assert!(v.get("weirdness_constraint").is_none());
    }

    #[test]
    fn billing_info_tolerates_missing_noncritical_fields() {
        // Only total_credits_left and plan are required.
        let r: BillingInfo =
            serde_json::from_str(r#"{"total_credits_left": 500, "plan": {"name": "Premier"}}"#)
                .unwrap();
        assert_eq!(r.total_credits_left, 500);
        assert_eq!(r.plan.name, "Premier");
        assert!(r.models.is_empty());
    }
}