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.
/api/profileRender a profile from your GPXPOST/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.
| Field | Type | Description |
|---|---|---|
gpxrequired | string | The raw GPX file contents as a non-empty string. |
optionsoptional | ChartOptions | Partial style overrides. Any field omitted falls back to the default style. See ChartOptions. |
markersoptional | Marker[] | 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:
| Field | Type | Description |
|---|---|---|
x-profile-nameoptional | header | URL-encoded track name from the GPX. |
x-profile-distance-kmoptional | header | Total distance in km, to one decimal. |
x-profile-markersoptional | header | Number of markers rendered. |
x-ratelimit-limitoptional | header | Max requests allowed in the current window. |
x-ratelimit-remainingoptional | header | Requests 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.
| Field | Type | Description |
|---|---|---|
coloroptional | string | Hex chart colour, e.g. "#9ae600". |
widthoptional | number | Image width in px (min 600). |
heightoptional | number | Image height in px (min 200). |
linesoptional | number | Number of stacked contour (ridgeline) lines. |
shiftoptional | number | Horizontal shift between consecutive lines, in px. |
strokeWidthoptional | number | Stroke width of the top ridgeline in px (0.5–8); stacked contour lines scale with it. |
showGridoptional | boolean | Draw the background grid. |
showAxesoptional | boolean | Draw the X and Y axes: lines, arrowheads, "Alt (m)"/"Dist (km)" captions and altitude tick labels. |
showKmLabelsoptional | boolean | Draw regular distance labels along the x-axis. |
showGradientoptional | boolean | Soft 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.
| Field | Type | Description |
|---|---|---|
idrequired | string | Unique marker id. |
namerequired | string | Label shown at the marker. |
distrequired | number | Position 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
- Maximum GPX payload size is 20 MB.
- Requests are rate limited per client IP to 30 requests per minute (fixed window). The
x-ratelimit-limitandx-ratelimit-remainingheaders report the current budget; a429response includes aretry-afterheader.
Error responses
Errors are returned as JSON (Content-Type: application/json) with an error message and an appropriate status code.
| Field | Type | Description |
|---|---|---|
400optional | Bad Request | Missing/empty gpx field, or an unreadable/invalid JSON body. |
413optional | Payload Too Large | GPX body exceeds the 20 MB limit. |
415optional | Unsupported Media Type | Content-Type is neither application/json nor an XML/GPX type. |
422optional | Unprocessable Entity | The GPX could not be parsed or rendered (details in the error message). |
429optional | Too Many Requests | Rate limit exceeded; retry after the window resets. |
{ "error": "Request body must include a non-empty 'gpx' string." }