Skip to content

API Documentation

JSON API reference for programmatic access to CLARA

Overview

CLARA exposes a JSON API alongside its web interface. All endpoints are available at https://clarascore.app and return application/json responses.

File upload endpoints use multipart/form-data. Accepted input formats: MusicXML (.mxl, .xml, .musicxml), MIDI (.mid), and ABC notation (.abc).

Error responses include an "error" field with a human-readable message and an appropriate HTTP status code (400 for bad input, 404 for not found, 500 for processing failures).

Maximum upload size: 16 MB.

Read-Only Endpoints

GET

/api/health

Health check endpoint. Returns the application status and version.

Parameters

None

Response

{
  "status": "ok",
  "version": "1.0"
}
GET

/api/styles

Returns all 16 arrangement styles with their names, descriptions, and available sub-variants.

Parameters

None

Response

{
  "hymn-block": {
    "name": "Hymn Block",
    "description": "Classic four-part hymn texture...",
    "variants": {
      "modern": {
        "name": "Modern",
        "description": "Contemporary voicings..."
      }
    }
  },
  "gospel": { ... },
  "bach-chorale": { ... }
}
GET

/api/ensembles

Returns all available ensemble types for orchestration, with names, instrument parts, and descriptions.

Parameters

None

Response

{
  "quartet": {
    "name": "String Quartet",
    "parts": "Violin I, Violin II, Viola, Cello",
    "description": "The classic chamber ensemble..."
  },
  "trio": { ... },
  "piano-trio": { ... },
  "wind-quintet": { ... },
  "brass-quintet": { ... },
  "custom": { ... }
}
GET

/api/orchestrate-styles

Returns orchestration style details including name, description, features list, and suggested tempo.

Parameters

None

Response

{
  "baroque": {
    "name": "Baroque",
    "description": "Contrapuntal lines, terraced dynamics...",
    "features": ["Detache articulation", "Trills & mordents", ...],
    "tempo": "Andante"
  },
  "classical": { ... },
  "romantic": { ... },
  "impressionist": { ... }
}
GET

/api/samples

Returns the library of built-in sample scores. These are public domain melodies you can use for testing without uploading your own files.

Query Parameters

Name Type Required Description
categorystringNoFilter by category: choral, vocal, instrumental

Example

GET /api/samples?category=choral

Response

[
  {
    "id": "amazing-grace",
    "title": "Amazing Grace",
    "composer": "Traditional",
    "category": "choral",
    "suggested_style": "hymn-block"
  },
  ...
]
GET

/api/samples/<id>/file

Download a sample score as a MusicXML file. The id comes from the /api/samples listing.

URL Parameters

Name Type Description
idstringSample score ID (e.g. amazing-grace)

Response

Binary MusicXML file download (.mxl). On error, returns JSON with an "error" field.

Example

GET /api/samples/amazing-grace/file
GET

/api/style-demo/<style_key>

Generates and returns a demo MIDI file (base64-encoded) for a given arrangement style. Used by the Styles page for audio previews. Results are cached on the server.

URL Parameters

Name Type Description
style_keystringStyle identifier (e.g. gospel, hymn-block)

Query Parameters

Name Type Required Description
variantstringNoSub-variant to demo (e.g. modern)

Response

{
  "midi_b64": "TVRoZAAAAAYAAQAC..."
}

Processing Endpoints

POST

/api/arrange

Generate a piano accompaniment from an uploaded melody. Returns download URLs for the arranged score and MIDI.

Content Type

multipart/form-data

Form Parameters

Name Type Required Description
filefileYesScore file (.mxl, .xml, .musicxml, .mid, .abc)
stylestringNoArrangement style (default: hymn-block). See /api/styles
variantstringNoStyle sub-variant (e.g. modern, traditional)
introstringNoAdd intro: on to enable
codastringNoAdd coda: on to enable
descantstringNoAdd soprano descant on final phrase: on to enable
combinedstringNoInclude melody with accompaniment: on to enable
modulateintegerNoSemitones to modulate up for final phrase (e.g. 2)
target_keystringNoTranspose to this key before arranging (e.g. G, Bb, f# minor)

Example (curl)

curl -X POST https://clarascore.app/api/arrange \
  -F "file=@melody.mxl" \
  -F "style=gospel" \
  -F "intro=on" \
  -F "target_key=G"

Response

{
  "job_id": "a1b2c3d4",
  "style": "gospel",
  "original_name": "melody.mxl",
  "download_url": "/download/a1b2c3d4/melody_gospel_arranged.mxl",
  "midi_url": "/midi/a1b2c3d4/melody_gospel_arranged.mxl"
}
POST

/api/orchestrate

Orchestrate a piano score for a chamber ensemble. Returns download URLs for the ensemble score and MIDI.

Content Type

multipart/form-data

Form Parameters

Name Type Required Description
filefileYesPiano score file (.mxl, .xml, .musicxml, .mid, .abc)
stylestringNoOrchestration style (default: classical). Options: baroque, classical, romantic, impressionist, cinematic, bartok, messiaen
ensemblestringNoEnsemble type (default: quartet). Options: quartet, trio, piano-trio, wind-quintet, brass-quintet, handbells
bell_sizestringNoHandbell set size (only for handbells ensemble, default: 3oct)

Example (curl)

curl -X POST https://clarascore.app/api/orchestrate \
  -F "file=@piano-score.mxl" \
  -F "style=romantic" \
  -F "ensemble=wind-quintet"

Response

{
  "job_id": "e5f6g7h8",
  "style": "romantic",
  "ensemble": "wind-quintet",
  "ensemble_name": "Wind Quintet",
  "original_name": "piano-score.mxl",
  "download_url": "/download/e5f6g7h8/piano-score_romantic_wind5.mxl",
  "midi_url": "/midi/e5f6g7h8/piano-score_romantic_wind5.mxl"
}
POST

/api/harmonize

Generate SATB or SAB vocal harmonization from a single melody line. Returns download URLs for the harmonized score and MIDI.

Content Type

multipart/form-data

Form Parameters

Name Type Required Description
filefileYesMelody file (.mxl, .xml, .musicxml, .mid, .abc)
voicesstringNoVoice arrangement (default: satb). Options: satb, sab
layoutstringNoScore layout (default: open). Options: open, closed
voicingstringNoVoicing style (default: full)
target_keystringNoTranspose to this key before harmonizing (e.g. G, Eb)

Example (curl)

curl -X POST https://clarascore.app/api/harmonize \
  -F "file=@melody.mxl" \
  -F "voices=satb" \
  -F "target_key=Eb"

Response

{
  "job_id": "i9j0k1l2",
  "voices": "satb",
  "target_key": "Eb",
  "original_name": "melody.mxl",
  "download_url": "/download/i9j0k1l2/melody_satb_harmonized.mxl",
  "midi_url": "/midi/i9j0k1l2/melody_satb_harmonized.mxl"
}
POST

/api/recommend-styles

Upload a score and get style recommendations based on its key, tempo, meter, and note density. Returns up to 5 suggestions ranked by fit score.

Content Type

multipart/form-data

Form Parameters

Name Type Required Description
filefileYesScore file to analyze (.mxl, .xml, .musicxml, .mid, .abc)

Example (curl)

curl -X POST https://clarascore.app/api/recommend-styles \
  -F "file=@melody.mxl"

Response

{
  "key": "G major",
  "mode": "major",
  "time_signature": "4/4",
  "tempo_bpm": 100,
  "measures": 16,
  "density": 4.5,
  "recommendations": [
    {
      "style": "hymn-block",
      "reason": "Simple meter, short form — classic hymn texture",
      "score": 90
    },
    {
      "style": "gospel",
      "reason": "Major key, 4/4 time — natural gospel feel",
      "score": 85
    }
  ]
}
POST

/api/hymn-setting/analyze

Analyze lyrics to detect their poetic meter and return matching hymn tunes from a library of 74 public domain melodies.

Content Type

application/json

JSON Body

Name Type Required Description
textstringYesLyrics text (multiple lines, one verse)

Example (curl)

curl -X POST https://clarascore.app/api/hymn-setting/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "Amazing grace how sweet the sound\nThat saved a wretch like me"}'

Response

Returns detected meter, syllable counts, and an array of matching tunes with their names, meters, and keys.

Error Handling

All error responses are JSON objects with an "error" string field:

{
  "error": "No file uploaded."
}

HTTP Status Codes

Code Meaning
200Success
400Bad request (missing file, invalid parameters, unsupported format)
404Resource not found (unknown sample ID, unknown style)
413File too large (exceeds 16 MB limit)
500Internal processing error (arrangement/orchestration/analysis failed)