78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
/**
|
|
* Suno API HTTP client with rate limiting, proxy support, retries and polling helpers.
|
|
*
|
|
* Rate limit: 20 requests per 10 seconds (sunoapi.org).
|
|
* Proxy support via SUNO_HTTP_PROXY / HTTPS_PROXY / HTTP_PROXY env vars.
|
|
*/
|
|
export interface SunoApiResponse<T = unknown> {
|
|
code: number;
|
|
msg: string;
|
|
data: T;
|
|
}
|
|
export interface SunoTrack {
|
|
id: string;
|
|
audio_url?: string;
|
|
audioUrl?: string;
|
|
source_audio_url?: string;
|
|
stream_audio_url?: string;
|
|
streamAudioUrl?: string;
|
|
source_stream_audio_url?: string;
|
|
image_url?: string;
|
|
imageUrl?: string;
|
|
source_image_url?: string;
|
|
prompt?: string;
|
|
model_name?: string;
|
|
modelName?: string;
|
|
title?: string;
|
|
tags?: string;
|
|
createTime?: string;
|
|
duration?: number;
|
|
}
|
|
export interface SunoLyricsVariant {
|
|
text?: string;
|
|
title?: string;
|
|
status?: string;
|
|
errorMessage?: string;
|
|
}
|
|
export interface SunoTaskData {
|
|
taskId: string;
|
|
parentMusicId?: string;
|
|
param?: string;
|
|
response?: {
|
|
taskId?: string;
|
|
data?: SunoTrack[] | SunoLyricsVariant[];
|
|
sunoData?: SunoTrack[];
|
|
};
|
|
status: string;
|
|
type?: string;
|
|
operationType?: 'generate' | 'extend' | 'upload_cover' | 'upload_extend';
|
|
errorCode?: number | null;
|
|
errorMessage?: string | null;
|
|
}
|
|
export declare class SunoClient {
|
|
private readonly baseUrl;
|
|
private readonly apiKey;
|
|
private readonly maxRequests;
|
|
private readonly windowMs;
|
|
private readonly proxyAgent?;
|
|
private readonly requestTimeoutMs;
|
|
private readonly maxRetries;
|
|
private requestTimestamps;
|
|
constructor(apiKey: string);
|
|
/**
|
|
* Enforce rate limit: max 20 requests per 10 seconds.
|
|
*/
|
|
private throttle;
|
|
request<T = unknown>(method: 'GET' | 'POST', path: string, body?: Record<string, unknown>): Promise<SunoApiResponse<T>>;
|
|
get<T = unknown>(path: string): Promise<SunoApiResponse<T>>;
|
|
post<T = unknown>(path: string, body: Record<string, unknown>): Promise<SunoApiResponse<T>>;
|
|
/**
|
|
* Poll task status until terminal state or timeout.
|
|
*/
|
|
pollTaskStatus(taskId: string, options?: {
|
|
intervalMs?: number;
|
|
maxAttempts?: number;
|
|
statusPath?: string;
|
|
}): Promise<SunoTaskData>;
|
|
}
|
|
//# sourceMappingURL=client.d.ts.map
|