> ## Documentation Index
> Fetch the complete documentation index at: https://docs.musicgpt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio To MIDI

> Processes an audio file and converts it into a MIDI file. Optionally generates a sonified .wav and/or a CSV of note events. This request is handled asynchronously.



## OpenAPI

````yaml POST /v1/audio_to_midi
openapi: 3.1.0
info:
  title: Musicgpt API
  version: 1.0.0
  description: API for retrieving conversion details by ID.
servers:
  - url: https://api.musicgpt.com/api/public
    description: Production server
security: []
paths:
  /v1/audio_to_midi:
    post:
      summary: Convert Audio to MIDI
      description: >-
        Processes an audio file and converts it into a MIDI file. Optionally
        generates a sonified .wav and/or a CSV of note events. This request is
        handled asynchronously.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                audio_url:
                  type: string
                  description: URL of the audio file to convert to MIDI.
                  example: https://example.com/audio.mp3
                audio_file:
                  type: string
                  format: binary
                  description: Audio file to upload and process directly.
                sonify_midi:
                  type: boolean
                  default: true
                  description: >-
                    If true, generates a .wav file that sonifies the MIDI
                    output.
                save_note_events:
                  type: boolean
                  default: true
                  description: If true, saves predicted note events as a CSV file.
                webhook_url:
                  type: string
                  description: Callback URL to receive conversion results.
                  example: https://your-webhook-url.com/callback
              anyOf:
                - required:
                    - audio_url
                - required:
                    - audio_file
      responses:
        '200':
          description: MIDI conversion task initiated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  task_id:
                    type: string
                    example: task789
                  message:
                    type: string
                    example: MIDI conversion task queued successfully
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Missing or invalid audio_url
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    example: Error during MIDI conversion
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: Python
          source: |-
            import requests

            url = "https://api.musicgpt.com/api/public/v1/audio_to_midi"
            headers = {"Authorization": "<<<api key>>>"}

            # Option 1: Use audio URL
            payload = {
                "audio_url": "https://example.com/audio_file.wav",
                "sonify_midi": True,
                "save_note_events": True,
                "webhook_url": "https://your-webhook-url.com/callback"
            }
            response = requests.post(url, headers=headers, data=payload)
            print(response.json())

            # Option 2: Upload local audio file
            payload = {
                "sonify_midi": True,
                "save_note_events": True,
                "webhook_url": "https://your-webhook-url.com/callback"
            }
            with open("audio.wav", "rb") as f:
                files = {"audio_file": f}
                response = requests.post(url, headers=headers, data=payload, files=files)
            print(response.json())
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````