Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .microfox/packagefox-build.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{"requests": []}
{
"requests": []
}
2 changes: 1 addition & 1 deletion .microfox/pr-usage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
4 changes: 2 additions & 2 deletions build-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
**Total Usage:** Tokens: 217527 | Cost: $0.9321
40 changes: 40 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions packages/suno/README.md
Original file line number Diff line number Diff line change
@@ -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)

100 changes: 100 additions & 0 deletions packages/suno/docSummary.md
Original file line number Diff line number Diff line change
@@ -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<MusicGenerationResponse> {
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.
48 changes: 48 additions & 0 deletions packages/suno/docs/createSunoSDK.md
Original file line number Diff line number Diff line change
@@ -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."
}
```
86 changes: 86 additions & 0 deletions packages/suno/docs/generateMusic.md
Original file line number Diff line number Diff line change
@@ -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<string, unknown>`): An object containing any additional, non-standard parameters to be sent to the music generation API.

**Return Value:**

- (`Promise<MusicGenerationResponse>`): 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();
```
Loading