diff --git a/.microfox/packagefox-build.json b/.microfox/packagefox-build.json index af4408b38..32d6910b6 100644 --- a/.microfox/packagefox-build.json +++ b/.microfox/packagefox-build.json @@ -1 +1,3 @@ -{"requests": []} +{ + "requests": [] +} \ No newline at end of file diff --git a/.microfox/pr-usage.json b/.microfox/pr-usage.json index 0967ef424..9e26dfeeb 100644 --- a/.microfox/pr-usage.json +++ b/.microfox/pr-usage.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/build-report.md b/build-report.md index af65c80b9..af1d6953d 100644 --- a/build-report.md +++ b/build-report.md @@ -2,8 +2,8 @@ | Step | Status | Details | Error | |------|--------|---------|-------| -| 🔍 analyze | ⏳ | currentFile: packages/apify/.foxes/packagefox-bug-build-1750627794192.json | | +| 🔍 analyze | ⏳ | currentFile: packages/suno/.foxes/packagefox-bug-build-1751806888266.json | | | ✏️ apply | ✅ | filesFixed: 1 | | --- -**Total Usage:** Tokens: 171757 | Cost: $0.6785 \ No newline at end of file +**Total Usage:** Tokens: 217527 | Cost: $0.9321 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 25e0a2556..0e5990379 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4086,6 +4086,14 @@ "resolved": "packages/stdlib", "link": true }, + "node_modules/@microfox/suno": { + "resolved": "packages/suno", + "link": true + }, + "node_modules/@microfox/suno-api": { + "resolved": "packages/suno-api", + "link": true + }, "node_modules/@microfox/task-kit": { "resolved": "packages/task-kit", "link": true @@ -22413,6 +22421,38 @@ "@microfox/tsconfig": "*" } }, + "packages/suno": { + "name": "@microfox/suno", + "version": "1.0.0", + "dependencies": { + "zod": "^3.24.2" + }, + "devDependencies": { + "@microfox/tsconfig": "*", + "@types/node": "^18", + "tsup": "^8", + "typescript": "5.6.3" + }, + "engines": { + "node": ">=20.0.0" + } + }, + "packages/suno-api": { + "name": "@microfox/suno-api", + "version": "0.0.1", + "dependencies": { + "zod": "^3.24.2" + }, + "devDependencies": { + "@microfox/tsconfig": "*", + "@types/node": "^18", + "tsup": "^8", + "typescript": "5.6.3" + }, + "engines": { + "node": ">=20.0.0" + } + }, "packages/task-kit": { "name": "@microfox/task-kit", "version": "1.0.3", diff --git a/packages/suno/README.md b/packages/suno/README.md new file mode 100644 index 000000000..403d3d56f --- /dev/null +++ b/packages/suno/README.md @@ -0,0 +1,24 @@ +# Suno SDK + +A TypeScript SDK for interacting with the Suno API. + +## Installation + +```bash +npm install @microfox/suno +``` + +## Environment Variables + +To use this package, you need to set the following environment variables: + +- `SUNO_API_KEY`: Your API key for the Suno API. To get your key, visit the Suno API Key Management Page, create an account or log in, navigate to the API section, and generate a new API key. ** (Required)** + +## API Reference + +For detailed documentation on the constructor and all available functions, please refer to the following files: + +- [**createSunoSDK** (Constructor)](./docs/constructors/createSunoSDK.md): Initializes the client. +- [generateMusic](./docs/functions/generateMusic.md) +- [generateSpeech](./docs/functions/generateSpeech.md) + diff --git a/packages/suno/docSummary.md b/packages/suno/docSummary.md new file mode 100644 index 000000000..31a50fad9 --- /dev/null +++ b/packages/suno/docSummary.md @@ -0,0 +1,100 @@ +## Suno API TypeScript SDK Summary + +This document summarizes the Suno API (v1.0.0) for generating audio, providing the necessary information for building a TypeScript SDK. The API uses Bearer token authentication for all endpoints. + +**Authentication:** + +* **Type:** `Bearer Token` +* **Header:** `Authorization: Bearer YOUR_API_KEY` +* **Obtaining API Key:** Visit the API Key Management Page (URL not provided in documentation, needs to be confirmed). +* **Security Considerations:** Keep your API Key secure and reset it immediately if compromised. + +**Global Error Handling:** (Not explicitly defined, needs clarification) +* The documentation doesn't specify standard error responses. The SDK should handle potential HTTP error codes (e.g., 400, 401, 500) and provide informative error messages. + +**Endpoints:** + +The provided documentation only gives a general overview of authentication and doesn't list specific endpoints. We need more information to create a comprehensive SDK. The following is a placeholder structure, assuming typical audio generation API functionality. This needs to be populated with actual endpoint details from the full Suno API documentation. + +**1. Music Generation (Placeholder - Requires Full API Spec)** + +* **Description:** Generates music based on provided parameters. (This is an assumption based on the "Next: Music Generation" link). +* **Endpoint:** `/music/generate` (Placeholder) +* **Method:** `POST` (Placeholder) +* **Request Headers:** + * `Authorization: Bearer YOUR_API_KEY` +* **Request Parameters/Body:** (Placeholder - Needs types and descriptions) + * `genre`: `string` (e.g., "rock", "jazz", "classical") + * `duration`: `number` (seconds) + * `tempo`: `number` (bpm) + * `other_parameters`: `object` (Depending on API specifics) +* **Response Format:** `application/json` (Placeholder) +* **Response Data Structure:** (Placeholder - Needs types and descriptions) + * `audio_url`: `string` (URL to download the generated music) + * `status`: `string` (e.g., "success", "failed") + * `message`: `string` (Optional message) + + +**2. Text-to-Speech (Placeholder - Requires Full API Spec)** + +* **Description:** Converts text into spoken audio. +* **Endpoint:** `/tts/generate` (Placeholder) +* **Method:** `POST` (Placeholder) +* **Request Headers:** + * `Authorization: Bearer YOUR_API_KEY` +* **Request Parameters/Body:** (Placeholder - Needs types and descriptions) + * `text`: `string` (The text to be converted to speech) + * `voice`: `string` (e.g., "male", "female", specific voice names) + * `language`: `string` (e.g., "en-US", "es-ES") +* **Response Format:** `application/json` or `audio/mpeg` (Placeholder - Needs confirmation) +* **Response Data Structure (if JSON):** (Placeholder - Needs types and descriptions) + * `audio_url`: `string` (URL to download the generated audio) + * `status`: `string` + * `message`: `string` + + +**Edge Cases:** + +* **Rate Limiting:** The documentation doesn't mention rate limits. The SDK should gracefully handle rate limit errors (e.g., 429 Too Many Requests) if they exist. +* **Error Handling:** Comprehensive error handling needs to be implemented based on the full API specification, including specific error codes and messages. + + +**TypeScript SDK Structure (Example):** + +```typescript +// Placeholder - Illustrative example. Adjust based on the full API spec. + +class SunoAPI { + private apiKey: string; + private baseUrl: string = "https://api.sunoapi.org/v1"; // Placeholder base URL + + constructor(apiKey: string) { + this.apiKey = apiKey; + } + + async generateMusic(params: MusicGenerationParams): Promise { + const response = await fetch(`${this.baseUrl}/music/generate`, { + method: "POST", + headers: { + "Authorization": `Bearer ${this.apiKey}`, + "Content-Type": "application/json", // Adjust if needed + }, + body: JSON.stringify(params), + }); + // ... handle response and errors ... + } + + // ... other methods for different endpoints ... +} + +interface MusicGenerationParams { + // ... parameter types ... +} + +interface MusicGenerationResponse { + // ... response types ... +} +``` + + +This summary provides a starting point for building a TypeScript SDK for the Suno API. The placeholders need to be replaced with concrete details from the complete API documentation. A robust SDK should handle authentication, requests, responses, error handling, and potentially rate limiting. diff --git a/packages/suno/docs/createSunoSDK.md b/packages/suno/docs/createSunoSDK.md new file mode 100644 index 000000000..f0815f3f2 --- /dev/null +++ b/packages/suno/docs/createSunoSDK.md @@ -0,0 +1,48 @@ +## Constructor: `createSunoSDK` + +The `createSunoSDK` function initializes and returns a new instance of the `SunoSDK` client. It configures the client with the necessary API key for authenticating with the Suno API. The API key is essential for all subsequent API calls. + +**Purpose:** +The main purpose of this constructor is to create and configure a `SunoSDK` object that is ready to interact with the Suno API. It handles the API key retrieval, which can be provided directly or from an environment variable, and throws an error if the key is not found, ensuring that the SDK instance is always properly authenticated. + +**Parameters:** + +- `options` (optional, `SunoSDKOptions` object): An optional configuration object. + - `apiKey` (optional, `string`): Your API key for the Suno API. If you do not provide the key here, the SDK will automatically look for it in the `SUNO_API_KEY` environment variable. An error will be thrown if the API key is not provided in either the options or the environment variable. + +**Return Value:** + +- (`SunoSDK`): An instance of the `SunoSDK` class, ready to be used for making API calls to generate music or speech. + +**Examples:** + +```typescript +// Example 1: Initialize using an environment variable +// Make sure to set the SUNO_API_KEY environment variable before running. +// export SUNO_API_KEY='your-api-key-here' + +import { createSunoSDK } from '@microfox/suno'; + +const sunoSDKFromEnv = createSunoSDK(); +``` + +```typescript +// Example 2: Initialize by passing the API key directly +import { createSunoSDK } from '@microfox/suno'; + +const apiKey = 'your-suno-api-key'; +const sunoSDKFromOptions = createSunoSDK({ apiKey }); +``` + +```typescript +// Example 3: Handling initialization errors +// This example will throw an error if the API key is not set in the environment +// or passed directly to the constructor. +import { createSunoSDK } from '@microfox/suno'; + +try { + const sunoSDK = createSunoSDK(); +} catch (error) { + console.error(error.message); // "API key is required. Please provide it in the constructor or set the SUNO_API_KEY environment variable." +} +``` diff --git a/packages/suno/docs/generateMusic.md b/packages/suno/docs/generateMusic.md new file mode 100644 index 000000000..62600468f --- /dev/null +++ b/packages/suno/docs/generateMusic.md @@ -0,0 +1,86 @@ +## Function: `generateMusic` + +Asynchronously generates a piece of music based on the provided parameters. This function validates the input and sends a request to the Suno API's `/music/generate` endpoint. + +**Purpose:** +This function is used to create original music compositions. You can specify the genre, duration, and tempo to tailor the generated music to your specific needs. It's ideal for applications requiring background music, soundtracks, or creative musical content. + +**Parameters:** + +- `params` (required, `MusicGenerationParams` object): An object containing the parameters for music generation. + - `genre` (required, `string`): The genre of the music to be generated (e.g., "rock", "jazz", "classical"). + - `duration` (required, `number`): The desired duration of the music in seconds. This must be a positive number. + - `tempo` (required, `number`): The tempo of the music in beats per minute (BPM). This must be a positive number. + - `otherParameters` (optional, `Record`): An object containing any additional, non-standard parameters to be sent to the music generation API. + +**Return Value:** + +- (`Promise`): A promise that resolves to a `MusicGenerationResponse` object containing the details of the generated music. + - `audioUrl` (`string`): A URL from which the generated music file can be downloaded. + - `status` (`string`): The status of the music generation request (e.g., "success", "failed"). + - `message` (optional, `string`): An optional message providing additional information about the status of the request. + +**Examples:** + +```typescript +import { createSunoSDK } from '@microfox/suno'; + +const sunoSDK = createSunoSDK({ apiKey: 'your-suno-api-key' }); + +// Example 1: Minimal usage with only required arguments +async function generateSimpleSong() { + try { + const result = await sunoSDK.generateMusic({ + genre: 'acoustic', + duration: 60, // 60 seconds + tempo: 120 // 120 BPM + }); + console.log('Music generation successful:', result); + // Expected output: { audioUrl: 'https://...', status: 'success' } + } catch (error) { + console.error('Error generating music:', error); + } +} + +generateSimpleSong(); +``` + +```typescript +// Example 2: Full usage with all optional arguments +async function generateCustomSong() { + try { + const result = await sunoSDK.generateMusic({ + genre: 'cinematic', + duration: 180, // 3 minutes + tempo: 90, + otherParameters: { + mood: 'epic', + instrumentation: ['strings', 'brass'] + } + }); + console.log('Custom music generation successful:', result); + } catch (error) { + console.error('Error generating custom music:', error); + } +} + +generateCustomSong(); +``` + +```typescript +// Example 3: Handling API errors +async function generateWithError() { + // Assuming the API returns an error for an unsupported genre + try { + await sunoSDK.generateMusic({ + genre: 'unsupported-genre', + duration: 30, + tempo: 100 + }); + } catch (error) { + console.error(error.message); // e.g., "HTTP error! status: 400 - Invalid genre" + } +} + +generateWithError(); +``` diff --git a/packages/suno/docs/generateSpeech.md b/packages/suno/docs/generateSpeech.md new file mode 100644 index 000000000..6cb2d8312 --- /dev/null +++ b/packages/suno/docs/generateSpeech.md @@ -0,0 +1,81 @@ +## Function: `generateSpeech` + +Asynchronously generates speech from text using the specified voice and language. This function validates the input parameters and sends a request to the Suno API's `/tts/generate` endpoint. + +**Purpose:** +This function is used to convert written text into natural-sounding spoken audio. It is useful for applications such as voiceovers, accessibility features, and interactive voice response (IVR) systems. + +**Parameters:** + +- `params` (required, `TextToSpeechParams` object): An object containing the parameters for the text-to-speech conversion. + - `text` (required, `string`): The text that you want to convert into speech. + - `voice` (required, `string`): The voice to use for the speech synthesis. This can be a generic identifier like "male" or "female", or a specific voice name provided by the Suno API. + - `language` (required, `string`): The language of the text, specified as a language code (e.g., "en-US" for American English, "es-ES" for Spanish). + +**Return Value:** + +- (`Promise`): A promise that resolves to a `TextToSpeechResponse` object containing the details of the generated audio. + - `audioUrl` (`string`): A URL from which the generated audio file can be downloaded. + - `status` (`string`): The status of the text-to-speech conversion (e.g., "success", "failed"). + - `message` (optional, `string`): An optional message providing additional information about the status of the request. + +**Examples:** + +```typescript +import { createSunoSDK } from '@microfox/suno'; + +const sunoSDK = createSunoSDK({ apiKey: 'your-suno-api-key' }); + +// Example 1: Basic text-to-speech conversion +async function generateBasicSpeech() { + try { + const result = await sunoSDK.generateSpeech({ + text: 'Hello, world! This is a test of the Suno text-to-speech API.', + voice: 'female', + language: 'en-US' + }); + console.log('Speech generation successful:', result); + // Expected output: { audioUrl: 'https://...', status: 'success' } + } catch (error) { + console.error('Error generating speech:', error); + } +} + +generateBasicSpeech(); +``` + +```typescript +// Example 2: Generating speech in a different language +async function generateSpanishSpeech() { + try { + const result = await sunoSDK.generateSpeech({ + text: 'Hola, mundo. Esta es una prueba de la API de texto a voz de Suno.', + voice: 'male', + language: 'es-ES' + }); + console.log('Spanish speech generation successful:', result); + } catch (error) { + console.error('Error generating Spanish speech:', error); + } +} + +generateSpanishSpeech(); +``` + +```typescript +// Example 3: Handling API errors +async function generateSpeechWithError() { + // Assuming the API returns an error for an invalid language code + try { + await sunoSDK.generateSpeech({ + text: 'This will fail.', + voice: 'female', + language: 'xx-XX' // Invalid language code + }); + } catch (error) { + console.error(error.message); // e.g., "HTTP error! status: 400 - Invalid language" + } +} + +generateSpeechWithError(); +``` diff --git a/packages/suno/docs/main.md b/packages/suno/docs/main.md new file mode 100644 index 000000000..403d3d56f --- /dev/null +++ b/packages/suno/docs/main.md @@ -0,0 +1,24 @@ +# Suno SDK + +A TypeScript SDK for interacting with the Suno API. + +## Installation + +```bash +npm install @microfox/suno +``` + +## Environment Variables + +To use this package, you need to set the following environment variables: + +- `SUNO_API_KEY`: Your API key for the Suno API. To get your key, visit the Suno API Key Management Page, create an account or log in, navigate to the API section, and generate a new API key. ** (Required)** + +## API Reference + +For detailed documentation on the constructor and all available functions, please refer to the following files: + +- [**createSunoSDK** (Constructor)](./docs/constructors/createSunoSDK.md): Initializes the client. +- [generateMusic](./docs/functions/generateMusic.md) +- [generateSpeech](./docs/functions/generateSpeech.md) + diff --git a/packages/suno/package-builder.json b/packages/suno/package-builder.json new file mode 100644 index 000000000..72a8ae929 --- /dev/null +++ b/packages/suno/package-builder.json @@ -0,0 +1,51 @@ +{ + "sdkMetadata": { + "apiName": "Suno", + "packageName": "@microfox/suno", + "title": "Suno SDK", + "description": "A TypeScript SDK for interacting with the Suno API.", + "keywords": [ + "suno", + "api", + "sdk", + "typescript", + "microfox" + ], + "authType": "auto", + "inputArgs": { + "query": "Create a package for Suno org", + "url": "https://docs.sunoapi.org/suno-api/intro", + "isBaseUrl": true + } + }, + "allLinks": [ + "https://docs.sunoapi.org/", + "https://sunoapi.org/", + "https://sunoapi.org/dashboard", + "https://docs.sunoapi.org/suno-api/intro", + "https://docs.sunoapi.org/zh-CN/suno-api/intro", + "https://docs.sunoapi.org/authentication", + "https://docs.sunoapi.org/category/suno-api", + "https://docs.sunoapi.org/suno-api/music-generation", + "https://docs.sunoapi.org/suno-api/lyrics-generation", + "https://docs.sunoapi.org/suno-api/wav-conversion", + "https://docs.sunoapi.org/suno-api/vocal-removal", + "https://docs.sunoapi.org/suno-api/music-video-generation", + "https://docs.sunoapi.org/suno-api/account-management", + "https://docs.sunoapi.org/category/file-upload-api", + "https://docs.sunoapi.org/file-upload-api/file-upload-api", + "https://docs.sunoapi.org/file-upload-api/file-upload", + "https://sunoapi.org/api-key" + ], + "filteredLinks": [ + "https://docs.sunoapi.org/suno-api/intro" + ], + "linkAnalysis": { + "documentationLinks": [ + "https://docs.sunoapi.org/suno-api/intro" + ], + "reason": "This link is the introduction page to the Suno API documentation and likely contains links to relevant sections such as authentication, endpoints, SDK examples, and integration guides.", + "setupInstructionsLink": "https://docs.sunoapi.org/suno-api/intro" + }, + "linksUpdatedAt": "2025-07-06T12:54:54.234Z" +} \ No newline at end of file diff --git a/packages/suno/package-info.json b/packages/suno/package-info.json new file mode 100644 index 000000000..d6c4b920d --- /dev/null +++ b/packages/suno/package-info.json @@ -0,0 +1,50 @@ +{ + "name": "@microfox/suno", + "title": "Suno SDK", + "description": "A TypeScript SDK providing convenient access to the Suno API for generating music and speech.", + "platformType": "tool", + "path": "packages/suno", + "dependencies": [ + "zod" + ], + "status": "semiStable", + "authEndpoint": "", + "oauth2Scopes": [], + "documentation": "https://www.npmjs.com/package/@microfox/suno", + "icon": "https://raw.githubusercontent.com/microfox-ai/microfox/refs/heads/main/logos/suno.svg", + "constructors": [ + { + "name": "createSunoSDK", + "description": "Create a new Suno SDK client through which you can interact with the API", + "auth": "apikey", + "apiType": "api_key", + "requiredKeys": [ + { + "key": "SUNO_API_KEY", + "displayName": "Suno API Key", + "description": "Your API key for the Suno API. To get your key, visit the Suno API Key Management Page, create an account or log in, navigate to the API section, and generate a new API key.", + "required": true + } + ], + "internalKeys": [], + "functionalities": [ + "generateMusic", + "generateSpeech" + ] + } + ], + "keyInstructions": { + "link": "", + "setupInfo": "To use the Suno SDK, you need to obtain an API key from Suno. Follow these steps:\n\n1. Visit the Suno API Key Management Page (URL to be confirmed with Suno).\n2. Create an account or log in to your existing account.\n3. Navigate to the API section and generate a new API key.\n4. Copy the API key and keep it secure.\n\nTo use the SDK, you can either pass the API key directly to the SDK constructor or set it as an environment variable:\n\n- Environment variable name: SUNO_API_KEY\n\nExample usage:\n\n```typescript\nimport { createSunoSDK } from '@microfox/suno';\n\n// Using environment variable\nconst sunoSDK = createSunoSDK();\n\n// Or passing the API key directly\nconst sunoSDK = createSunoSDK({ apiKey: 'your-api-key-here' });\n```\n\nMake sure to keep your API key secure and never share it publicly. If you suspect your API key has been compromised, reset it immediately through the Suno API Key Management Page.\n\nThe SDK uses the Fetch API, which is available in Node.js environments version 18 and above. If you're using an older version of Node.js, you may need to use a polyfill for Fetch." + }, + "extraInfo": [ + "To use the Suno SDK, you need to obtain an API key from Suno. Follow these steps:\n\n1. Visit the Suno API Key Management Page (URL to be confirmed with Suno).\n2. Create an account or log in to your existing account.\n3. Navigate to the API section and generate a new API key.\n4. Copy the API key and keep it secure.\n\nTo use the SDK, you can either pass the API key directly to the SDK constructor or set it as an environment variable:\n\n- Environment variable name: SUNO_API_KEY\n\nExample usage:\n\n```typescript\nimport { createSunoSDK } from '@microfox/suno';\n\n// Using environment variable\nconst sunoSDK = createSunoSDK();\n\n// Or passing the API key directly\nconst sunoSDK = createSunoSDK({ apiKey: 'your-api-key-here' });\n```\n\nMake sure to keep your API key secure and never share it publicly. If you suspect your API key has been compromised, reset it immediately through the Suno API Key Management Page.\n\nThe SDK uses the Fetch API, which is available in Node.js environments version 18 and above. If you're using an older version of Node.js, you may need to use a polyfill for Fetch." + ], + "authType": "apikey", + "devDependencies": [ + "@microfox/tsconfig", + "@types/node", + "tsup", + "typescript" + ] +} \ No newline at end of file diff --git a/packages/suno/package.json b/packages/suno/package.json new file mode 100644 index 000000000..307044de8 --- /dev/null +++ b/packages/suno/package.json @@ -0,0 +1,56 @@ +{ + "name": "@microfox/suno", + "version": "1.0.0", + "description": "A TypeScript SDK for interacting with the Suno API.", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist/**/*", + "CHANGELOG.md" + ], + "scripts": { + "build": "tsup", + "build:watch": "tsup --watch", + "clean": "rm -rf dist", + "lint": "eslint \"./**/*.ts*\"", + "prettier-check": "prettier --check \"./**/*.ts*\"" + }, + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, + "dependencies": { + "zod": "^3.24.2" + }, + "devDependencies": { + "@microfox/tsconfig": "*", + "@types/node": "^18", + "tsup": "^8", + "typescript": "5.6.3" + }, + "publishConfig": { + "access": "public" + }, + "engines": { + "node": ">=20.0.0" + }, + "homepage": "https://github.com/microfox-ai/microfox", + "repository": { + "type": "git", + "url": "git+https://github.com/microfox-ai/microfox.git" + }, + "bugs": { + "url": "https://github.com/microfox-ai/microfox/issues" + }, + "keywords": [ + "suno", + "api", + "sdk", + "typescript", + "microfox" + ] +} \ No newline at end of file diff --git a/packages/suno/scrapedDocs/base-.json b/packages/suno/scrapedDocs/base-.json new file mode 100644 index 000000000..481a198fc --- /dev/null +++ b/packages/suno/scrapedDocs/base-.json @@ -0,0 +1,5 @@ +{ + "url": "https://docs.sunoapi.org/suno-api/intro", + "content": "Skip to main content\nSunoApi.org\nSuno APIIntroduction\nOn this page\nVersion: 1.0.0\nintro\n\nAPI documentation for audio generation services\n\nAuthentication​\nHTTP: Bearer Auth\n🔑 API Authentication\n\nAll endpoints require authentication using Bearer Token.\n\nGet API Key​\nVisit the API Key Management Page to obtain your API Key\nUsage​\n\nAdd to request headers:\n\nAuthorization: Bearer YOUR_API_KEY\n\n\n⚠️ Note:\n\nKeep your API Key secure and do not share it with others\nIf you suspect your API Key has been compromised, reset it immediately from the management page\n\nSecurity Scheme Type:\n\n\t\n\nhttp\n\n\n\n\nHTTP Authorization Scheme:\n\n\t\n\nbearer\n\n\n\n\nBearer format:\n\n\t\n\nAPI Key\n\nContact\n\nTechnical Support: support@sunoapi.org\n\nPrevious\nSuno API\nNext\nMusic Generation\nCopyright © 2025 SunoApi.org, Inc. Built with Docusaurus.", + "updatedAt": "2025-07-06T12:55:01.920Z" +} \ No newline at end of file diff --git a/packages/suno/src/SunoSdk.ts b/packages/suno/src/SunoSdk.ts new file mode 100644 index 000000000..134a6b59b --- /dev/null +++ b/packages/suno/src/SunoSdk.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { SunoSDKOptions, MusicGenerationParams, MusicGenerationResponse, TextToSpeechParams, TextToSpeechResponse } from './types'; +import { musicGenerationParamsSchema, textToSpeechParamsSchema } from './schemas'; + +class SunoSDK { + private apiKey: string; + private baseUrl: string = 'https://api.sunoapi.org/v1'; + + constructor(options?: SunoSDKOptions) { + this.apiKey = options?.apiKey || process.env.SUNO_API_KEY || ''; + if (!this.apiKey) { + throw new Error('API key is required. Please provide it in the constructor or set the SUNO_API_KEY environment variable.'); + } + } + + private async request(endpoint: string, method: string, body?: unknown): Promise { + const response = await fetch(`${this.baseUrl}${endpoint}`, { + method, + headers: { + 'Authorization': `Bearer ${this.apiKey}`, + 'Content-Type': 'application/json', + }, + body: body ? JSON.stringify(body) : undefined, + }); + + if (!response.ok) { + let errorMessage = `HTTP error! status: ${response.status}`; + try { + const errorBody = await response.json(); + errorMessage += ` - ${errorBody.message || JSON.stringify(errorBody)}`; + } catch (e) { + // If parsing fails, we'll just use the status code + } + throw new Error(errorMessage); + } + + return response.json() as Promise; + } + + async generateMusic(params: MusicGenerationParams): Promise { + const validatedParams = musicGenerationParamsSchema.parse(params); + return this.request('/music/generate', 'POST', validatedParams); + } + + async generateSpeech(params: TextToSpeechParams): Promise { + const validatedParams = textToSpeechParamsSchema.parse(params); + return this.request('/tts/generate', 'POST', validatedParams); + } +} + +export function createSunoSDK(options?: SunoSDKOptions): SunoSDK { + return new SunoSDK(options); +} diff --git a/packages/suno/src/index.ts b/packages/suno/src/index.ts new file mode 100644 index 000000000..ec7263b01 --- /dev/null +++ b/packages/suno/src/index.ts @@ -0,0 +1,3 @@ +export { createSunoSDK } from './SunoSdk'; +export * from './types'; +// Note: We don't export schemas as they are used internally diff --git a/packages/suno/src/schemas/index.ts b/packages/suno/src/schemas/index.ts new file mode 100644 index 000000000..7794df473 --- /dev/null +++ b/packages/suno/src/schemas/index.ts @@ -0,0 +1,26 @@ +import { z } from 'zod'; + +export const musicGenerationParamsSchema = z.object({ + genre: z.string().describe('The genre of the music to generate (e.g., "rock", "jazz", "classical")'), + duration: z.number().positive().describe('The duration of the music in seconds'), + tempo: z.number().positive().describe('The tempo of the music in beats per minute (bpm)'), + otherParameters: z.record(z.unknown()).optional().describe('Additional parameters for music generation'), +}); + +export const textToSpeechParamsSchema = z.object({ + text: z.string().describe('The text to be converted to speech'), + voice: z.string().describe('The voice to use (e.g., "male", "female", or specific voice names)'), + language: z.string().describe('The language code (e.g., "en-US", "es-ES")'), +}); + +export const musicGenerationResponseSchema = z.object({ + audioUrl: z.string().url().describe('URL to download the generated music'), + status: z.string().describe('Status of the music generation (e.g., "success", "failed")'), + message: z.string().optional().describe('Optional message providing additional information'), +}); + +export const textToSpeechResponseSchema = z.object({ + audioUrl: z.string().url().describe('URL to download the generated audio'), + status: z.string().describe('Status of the text-to-speech conversion'), + message: z.string().optional().describe('Optional message providing additional information'), +}); diff --git a/packages/suno/src/types/index.ts b/packages/suno/src/types/index.ts new file mode 100644 index 000000000..855c7359c --- /dev/null +++ b/packages/suno/src/types/index.ts @@ -0,0 +1,34 @@ +import { z } from 'zod'; + +export interface SunoSDKOptions { + apiKey?: string; +} + +export interface MusicGenerationResponse { + audioUrl: string; + status: string; + message?: string; +} + +export interface TextToSpeechResponse { + audioUrl: string; + status: string; + message?: string; +} + +// Zod schemas +export const musicGenerationParamsSchema = z.object({ + genre: z.string().describe('The genre of the music to generate (e.g., "rock", "jazz", "classical")'), + duration: z.number().positive().describe('The duration of the music in seconds'), + tempo: z.number().positive().describe('The tempo of the music in beats per minute (bpm)'), + otherParameters: z.record(z.unknown()).optional().describe('Additional parameters for music generation'), +}); + +export const textToSpeechParamsSchema = z.object({ + text: z.string().describe('The text to be converted to speech'), + voice: z.string().describe('The voice to use (e.g., "male", "female", or specific voice names)'), + language: z.string().describe('The language code (e.g., "en-US", "es-ES")'), +}); + +export type MusicGenerationParams = z.infer; +export type TextToSpeechParams = z.infer; \ No newline at end of file diff --git a/packages/suno/tsconfig.json b/packages/suno/tsconfig.json new file mode 100644 index 000000000..9b13fd070 --- /dev/null +++ b/packages/suno/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "@microfox/tsconfig/ts-library.json", + "include": ["."], + "exclude": ["*/dist", "dist", "build", "node_modules"] +} \ No newline at end of file diff --git a/packages/suno/tsup.config.ts b/packages/suno/tsup.config.ts new file mode 100644 index 000000000..9480ab1bf --- /dev/null +++ b/packages/suno/tsup.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig([ + { + entry: ['src/index.ts'], + format: ['cjs', 'esm'], + dts: true, + sourcemap: true, + }, +]); \ No newline at end of file diff --git a/packages/suno/turbo.json b/packages/suno/turbo.json new file mode 100644 index 000000000..48d0cfcd4 --- /dev/null +++ b/packages/suno/turbo.json @@ -0,0 +1,12 @@ +{ + "extends": [ + "//" + ], + "tasks": { + "build": { + "outputs": [ + "**/dist/**" + ] + } + } +} \ No newline at end of file diff --git a/scripts/package-lock.json b/scripts/package-lock.json index 76d8260e0..6545037db 100644 --- a/scripts/package-lock.json +++ b/scripts/package-lock.json @@ -43,7 +43,6 @@ } }, "..": { - "name": "microfox", "extraneous": true, "workspaces": [ "apps/*",