API Reference

Profile API

Generate a race-style elevation profile from a GPX file over HTTP. Send your GPX to POST /api/profile and get an image/svg+xml response back — the same rendering pipeline the web app uses.

POST/api/profileRender a profile from your GPX

POST/api/profile

Renders an elevation profile and returns it as an SVG document. Two request shapes are accepted, selected by the Content-Type header.

JSON body

Send Content-Type: application/json with a body containing your GPX plus optional styling. This is the only way to customise options and markers.

FieldTypeDescription
gpxrequiredstringThe raw GPX file contents as a non-empty string.
optionsoptionalChartOptionsPartial style overrides. Any field omitted falls back to the default style. See ChartOptions.
markersoptionalMarker[]Course markers to draw. When omitted, no custom markers are added. See Marker.
formatoptional"svg"Reserved; SVG is currently the only output.

Raw GPX body

Send Content-Type: application/gpx+xml (or any */xml) with the raw file as the body. The profile is rendered at the default style; options and markers cannot be set this way.

Response

On success: 200 OK with Content-Type: image/svg+xml; charset=utf-8 and the SVG as the body. A few computed stats are exposed as response headers so you don't have to parse the SVG:

FieldTypeDescription
x-profile-nameoptionalheaderURL-encoded track name from the GPX.
x-profile-distance-kmoptionalheaderTotal distance in km, to one decimal.
x-profile-markersoptionalheaderNumber of markers rendered.
x-ratelimit-limitoptionalheaderMax requests allowed in the current window.
x-ratelimit-remainingoptionalheaderRequests remaining in the current window.

Examples

Raw GPX, default style:

curl -X POST https://gpx-profile.vercel.app/api/profile \
  -H "Content-Type: application/gpx+xml" \
  --data-binary @track.gpx \
  -o profile.svg

JSON body with custom style and markers:

curl -X POST https://gpx-profile.vercel.app/api/profile \
  -H "Content-Type: application/json" \
  -o profile.svg \
  -d '{
    "gpx": "<gpx>...</gpx>",
    "options": { "color": "#9ae600", "width": 1310, "height": 300, "showGradient": true },
    "markers": [
      { "id": "m1", "name": "Start",  "dist": 0,    "icon": "start" },
      { "id": "m2", "name": "Aid 1",  "dist": 42.5, "icon": "food"  },
      { "id": "m3", "name": "Finish", "dist": 90,   "icon": "flag"  }
    ]
  }'

From JavaScript (reading GPX text in the browser):

const gpx = await file.text();
const res = await fetch("/api/profile", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ gpx, options: { color: "#9ae600" } }),
});
if (!res.ok) throw new Error((await res.json()).error);
const svg = await res.text();

ChartOptions

Passed as options in the JSON body. Every field is optional; omitted fields keep their default.

FieldTypeDescription
coloroptionalstringHex chart colour, e.g. "#9ae600".
widthoptionalnumberImage width in px (min 600).
heightoptionalnumberImage height in px (min 200).
linesoptionalnumberNumber of stacked contour (ridgeline) lines.
shiftoptionalnumberHorizontal shift between consecutive lines, in px.
strokeWidthoptionalnumberStroke width of the top ridgeline in px (0.5–8); stacked contour lines scale with it.
showGridoptionalbooleanDraw the background grid.
showAxesoptionalbooleanDraw the X and Y axes: lines, arrowheads, "Alt (m)"/"Dist (km)" captions and altitude tick labels.
showKmLabelsoptionalbooleanDraw regular distance labels along the x-axis.
showGradientoptionalbooleanSoft gradient fill and shaded lines; off = flat lines in the picked colour.
backgroundoptional"white" | "transparent"Background fill of the SVG.

Marker

Each entry in the markers array labels a point along the course.

FieldTypeDescription
idrequiredstringUnique marker id.
namerequiredstringLabel shown at the marker.
distrequirednumberPosition along the course, in km.
iconrequired"none" | "food" | "water" | "flag" | "start" | "runner"Badge icon. A runner marks a position on the course rather than a fixed feature.

Limits & rate limiting

Error responses

Errors are returned as JSON (Content-Type: application/json) with an error message and an appropriate status code.

FieldTypeDescription
400optionalBad RequestMissing/empty gpx field, or an unreadable/invalid JSON body.
413optionalPayload Too LargeGPX body exceeds the 20 MB limit.
415optionalUnsupported Media TypeContent-Type is neither application/json nor an XML/GPX type.
422optionalUnprocessable EntityThe GPX could not be parsed or rendered (details in the error message).
429optionalToo Many RequestsRate limit exceeded; retry after the window resets.
{ "error": "Request body must include a non-empty 'gpx' string." }