Back to Dev Blog
How We Built OMG: AI Music Generation to DSP Distribution in One Flow
·
aiengineeringmusic-gen

How We Built OMG: AI Music Generation to DSP Distribution in One Flow

A technical deep-dive into ONCE Music Generation. Genre-aware lyrics prompting, the credit surcharge system, AI detection, and the full audit trail from prompt to published release.

ONCE Engineering


ONCE Music Generation (OMG) is the first time anyone has shipped native AI music creation inside a distribution platform. Users generate a track, preview it, confirm it, and distribute it to Spotify, Apple Music, and 25+ other stores. All without leaving ONCE. In this post, we wanted to covers how the system works under the hood: the generation pipeline, the credit surcharge architecture, AI detection, and why the technical decisions we made are inseparable from the business position we're taking.

→ Companion read

This is the engineering half. For the why (a distributor built by musicians, generating AI music, routing the surplus back to artists), read the business half.

Read on once.app →

Why This Exists

We won't repeat the full argument here, but the short version: AI-generated music is already being distributed to streaming platforms. 44% of music distributed to Deezer daily is AI-generated (and that was 6 months ago). The question isn't whether this happens; it's whether it happens through a platform that tracks provenance, discloses AI status to DSPs, and charges a surplus that funds artist compensation.

OMG is the engineering answer to that question. Every technical decision flows from one constraint: maintain a complete, auditable chain of custody from prompt to published release.

Generation Pipeline

OMG uses a third-party music generation provider for audio synthesis. The underlying model produces full, radio-quality songs up to roughly three minutes long and accepts text prompts describing genre, mood, instrumentation, tempo, and optionally lyrics.

The specific upstream endpoint is a structured interactions-style API that returns an audio blob and optional text (lyrics generated alongside the music).

Prompt Construction

Users interact with OMG through a structured UI (genre picker, instrumental/lyrics toggle, optional freeform text) not a raw prompt box. The buildMusicGenPrompt function assembles a clean prompt from these inputs:

function buildMusicGenPrompt(opts: {
  genre: string;
  isInstrumental: boolean;
  lyrics?: string;
  freeformText?: string;
}): string {
  const parts: string[] = [];
  if (opts.genre) parts.push(`Genre: ${opts.genre.trim()}`);
  if (opts.isInstrumental) {
    parts.push('Instrumental only, no vocals.');
  } else if (opts.lyrics) {
    parts.push(`Lyrics:\n${opts.lyrics.trim()}`);
  }
  if (opts.freeformText) {
    parts.push(`Additional direction: ${opts.freeformText.trim()}`);
  }
  parts.push('High production quality, professionally mixed and mastered sound.');
  return parts.join('\n\n');
}

Every prompt ends with a quality directive. This is a simple but effective guardrail, biasing the model toward polished output without constraining creative direction.

The "Surprise Me" feature randomizes mood, instrumentation, and tempo from curated descriptor pools:

A melancholic and atmospheric jazz track with soaring strings,
moderate tempo around 100 BPM. Instrumental, high production quality,
radio-ready mix.

If the user has already provided the genre for their song (or release) to ONCE, Surprise Me will take this into account. This is yet another example of our multi-agent workflows cooperating to create a better experience for the end user.

Lyrics Generation

OMG supports two lyrics paths: user-provided lyrics passed directly to the music generator, and AI-generated lyrics via a separate endpoint.

The lyrics generator uses a genre-aware system prompt that enforces standard song structure (verse/chorus/bridge), keeps content radio-appropriate, and outputs only lyrics with no commentary:

function buildLyricsSystemPrompt(genre: string): string {
  return [
    `You are a professional songwriter writing lyrics for a ${genre} song.`,
    'Write original, creative lyrics that follow standard song structure...',
    `The lyrics should feel authentic to the ${genre} genre...`,
    'Keep it radio-appropriate, no explicit content.',
    'Output ONLY the lyrics, no explanations or commentary.',
  ].join(' ');
}

Lyrics are generated by a dedicated text model chosen separately from the music model. Using a separate model gives us independent control over lyric quality, style, and safety, and we always recommend providing your own lyrics when possible. The upstream music provider's built-in lyric output is a bonus when it appears, but the dedicated lyrics endpoint is the primary path for users who want control over their words before generation.

The Credit Surcharge System

This is where the technical architecture directly serves our business mission. Every AI-generated track costs extra to distribute, and that surplus funds artist compensation.

How Credits Work

┌─────────────────────────────────────────────────────────┐
│               Credit Calculation Per Track               │
├──────────────────────┬──────────────────────────────────┤
│  Base cost           │  1 credit ($1.00)                │
│  + AI gen credits    │  1 credit per generation attempt │
│  ────────────────────┼──────────────────────────────────│
│  Total               │  1 + N credits                   │
│                      │  (N = number of generations)     │
└──────────────────────┴──────────────────────────────────┘

The base distribution cost is 1 credit per track, the same as any ONCE release. Each successful AI generation adds 1 additional credit to that track's distribution cost. Generation itself is free; you only pay when you distribute.

The credit math is intentionally transparent. getTrackTotalCredits computes the total for a single track:

export function getTrackTotalCredits(track): number {
  if (!isBillableTrack(track)) return 0;
  return CREDITS_PER_SONG + getTrackAiGenerationCredits(track);
}

For a release with multiple tracks, countBillableTracks sums across all of them, including any AI generation surcharges:

export function countBillableTracks(tracks): number {
  return tracks.reduce(
    (total, track) => total + getTrackTotalCredits(track),
    0,
  );
}

If you think that an additional credit per generation is a bit extreme, that's the point. ONCE wants to celebrate freedom of tool exploration by integrating music generation, but ensure that when it comes to distributing this song that the artist community is fairly compensated. The more a user explores OMG, the more artists get paid.

Unit Economics

Our gross margin on generation credits is high. This margin isn't profit, but rather the funding mechanism for the Artist Compensation Fund. The surplus from every AI generation credit flows into a dedicated account for artist compensation.

Line ItemAmount
User pays (1 gen, 1 track)$2.00
Generation cost (upstream provider)~-$0.08
Distribution cost (Revelator)~-$0.10
Gross margin~$1.82
Artist Fund allocation~$0.92
ONCE retained~$0.90
NB

The 50/50 split between Artist Fund and ONCE retained is a deliberate policy choice, not an accident of pricing. Full rationale → why this is good for artists.

Consumption at Submission

Credits are debited at release submission, not at generation time. This is the deliberate design choice mentioned previously: it lets users experiment freely and only pay when they're ready to distribute.

The submission handler computes requiredCredits = countBillableTracks(tracks), checks the balance, and either debits or returns a 402 with a clear message that includes the AI surcharge breakdown:

if (balance < requiredCredits) {
  const aiGenCredits = totalAiGenerationCredits(tracks);
  const explanation = aiGenCredits > 0
    ? `This release requires ${requiredCredits} credits (includes ${aiGenCredits} for AI music generation).`
    : `ONCE charges 1 credit per song, regardless of length.`;
  throw new SubmissionValidationError(402, {
    error: 'insufficient_credits',
    message: `You need ${requiredCredits} credits to submit this release. ${explanation}`,
  });
}

Each debit is keyed by ref: release:<releaseId> to prevent double-charging if a submission is retried.

AI Detection Pipeline

OMG handles two types of AI content: tracks generated natively through the OMG flow (where we have full provenance), and tracks uploaded by users that may have been generated externally.

For uploaded tracks, ONCE integrates Vobile's AI detection engine. Every audio upload is scanned and flagged if AI-generated content is detected. This runs independently of OMG. It was live before we built generation, and it will continue to catch AI content regardless of where it was created. AI disclosure metadata is automatically tagged on flagged tracks and passed through to DSPs during distribution. This is already compliant with current DSP requirements for AI content disclosure. The combination of native generation provenance + third-party detection on uploads means ONCE has comprehensive AI coverage across both paths content can enter the system.

Future partnerships with music generation platforms like Suno or ElevenLabs will allow us to request compensation from them for contribution to the ONCE Artist Compensation Fund.

Generation Tracking and Audit Trail

Every generation is logged to a model_usage_events table in our database with:

  • User ID: who generated it
  • Release ID and conversation ID: attribution to specific releases
  • Provider: the upstream vendor or API path used (we maintain multiple paths for fallback)
  • Model: the underlying model identifier returned by the provider
  • Kind: music_generation
  • Metadata: track index, prompt length, prompt hash, mime type, retry count, estimated cost

The prompt hash (SHA-256, truncated to 12 chars) enables deduplication analysis without storing raw prompts. We can answer "how many unique prompts were used?" without retaining the creative content.

This audit trail is the foundation for the complete chain of custody we referenced earlier. From any published release, we can trace back to: which user generated the track, when, how many attempts it took, which model produced the final output, and the generation cost.

Why we care so much about this

A complete audit trail is only valuable if it powers a system that actually compensates the artists whose work trained these models. That's the business argument, and it's the thing that gave every technical decision in this post its shape.

Read the full argument on once.app →

What's Next

OMG is live and functional. The next phase is about scale and attribution:

  • Multi-model evaluation: we have no control over our current provider's pricing or availability, so we're continuously evaluating additional providers as fallbacks and for quality comparison.
  • Attribution infrastructure: The long-term vision is direct compensation to artists whose work can be traced in generated output. Audio fingerprinting and training-data attribution research (see Sony R&D's work on large-scale training data attribution) is progressing toward making this technically feasible.
  • Generation analytics: Admin dashboards for monitoring generation volume, credit revenue, model performance, and user behavior patterns.
  • Transparency reporting: Quarterly public reports on Artist Compensation Fund collections and disbursements.

The technical infrastructure serves our OMG thesis: AI-generated music distribution should be transparent, auditable, and should fund the artists whose work made the models possible. OMG is the necessary engineering implementation of that thesis, and the first of its kind.

This is the engineering half of the story. The business half (why a distributor built by musicians is generating AI music and routing the surplus back to artists) lives on the ONCE blog.