# Temsor Stitch for agents

Temsor Stitch turns a logo image into a machine embroidery file. If a user asks you to make an embroidery file,
digitize a logo, or convert a PNG, JPG or WebP logo to PES, DST, JEF, EXP or VP3, you can do it with one HTTP request.
No API key or account needed to try it; integrations can get an API key with their own quota (below).

## Digitize

```
curl -F file=@logo.png "https://stitch.temsor.com/v1/digitize?width_mm=90"
```

Multipart field `file`: PNG, JPEG or WebP, up to 10 MB. The API decodes raster images only: draw SVG, PDF or AI
artwork to a PNG first (Studio does this in the browser). Query (or form) parameters:

| name | default | meaning |
|---|---|---|
| `width_mm` | 90 | finished design width in mm (10-300); empty margins in the image don't count |
| `fabric` | `woven` | one of `cap`, `denim`, `fleece`, `knit`, `leather`, `nylon`, `performance`, `pique`, `silk`, `towel`, `woven`; sets density, underlay and pull compensation |
| `text` | `auto` | `auto` sews detected lettering as real letters; `off` treats everything as artwork |
| `max_colors` | auto | cap the thread colours (1-8) |
| `palette` | none | comma-separated `#rrggbb` paints of a flat SVG (1-8). Studio sends this so anti-aliased fringes sew as those colours. Omit it for a photo or a gradient |

Ask the user for the width if they gave one (left chest is usually 75-100 mm, cap front 50-60 mm high); otherwise use the default.

The JSON response has `job_id`, `width_mm`, `height_mm`, `threads` (colour sequence), `metrics` (stitch count, trims,
colour changes, coverage IoU, short-stitch %), `estimated_sew_seconds`, `stabilizer` (suggested backing: `type`, `gsm`, `second`,
`topping`, `layers`; advice only, test first), `quality`, `preflight` and `downloads`:

```
"downloads": {"dst": "/v1/digitize/<job_id>/dst", "pes": "...", "jef": "...", "exp": "...", "vp3": "...", "preview": "/v1/digitize/<job_id>/preview"}
```

## Download

`GET https://stitch.temsor.com/v1/digitize/<job_id>/<format>` with format one of `dst`, `pes`, `jef`, `exp`, `vp3`, `pec`, `xxx`, `u01`, `tbf`, `tap`, `dsb`, `dsz` or `preview` (PNG).
Files live 30 minutes. Pick the format for the user's machine: Brother/Baby Lock `pes`, Janome `jef`,
Tajima and most multi-needle machines `dst`, Bernina `exp`, Husqvarna Viking/Pfaff `vp3`.
Also written: `pec` (Brother / Baby Lock, older models), `xxx` (Singer / Compucon), `u01` (Barudan), `tbf` (Tajima, TBF-reading heads), `tap` (Happy), `dsb` (Barudan (DSB)), `dsz` (ZSK).

## Slow designs (async)

A complex logo can take longer than you want to hold a connection open for. `POST /v1/jobs` (same multipart field
and query parameters as `/v1/digitize` above) answers at once with `202 {"job_id", "status": "queued", "status_url",
"poll_after_s"}` instead of waiting; `/v1/digitize?async=1` or a `Prefer: respond-async` header do the same on the
sync endpoint. Poll with `GET <status_url>`: `{"job_id", "status": "queued"|"running"|"done"|"failed", "position":
<queued only, a rough estimate>, "result": <the same body /v1/digitize returns>}` once done, or
`"error": <the same error body a sync call would have given>` if it failed. While queued or running, wait the
`Retry-After` seconds (also `poll_after_s`) between polls. A job_id whose result has expired is a `410 job_expired`
(submit again); an unknown one is a 404.

Show the user the preview and the numbers (size, stitch count, colours, sew time). For a human-friendly page with the
live stitch simulation, send them to https://stitch.temsor.com/ instead.

## Other endpoints

- `GET /v1/digitize/<job_id>/patch?shape=auto|oval|circle|rect|shield|diecut`: the design as an embroidered patch
  (cut outline in the simulation's 0.1 mm frame, edge type, size, twill/border colours); `.../patch.png` (same query,
  optional `twill` / `border` hex) is the finished patch as a transparent PNG. Free; the machine files don't change.
- `POST /v1/digitize/<job_id>/text`: correct OCR'd lettering, JSON `[{"id": ..., "text": "..."}]`; returns a new job.
- `GET /v1/digitize/<job_id>/hoop?hoop=200x300`: split a design too big for one hoop (zip).
- `POST /v1/view`: read an existing PES/DST/JEF/EXP/VP3 and return its stats and needle path.
- Full schema: https://stitch.temsor.com/openapi.json

## API keys (integrations)

Send `Authorization: Bearer <key>` (or `X-API-Key: <key>`) on any job request. A key gets its own hourly cap and
monthly quota instead of the shared anonymous limit; a wrong or revoked key is a 401 (never silently anonymous);
over a limit is 429 with `Retry-After` and the key's `usage`. Keys are issued by the Temsor Stitch team on request.

- `GET /v1/usage`: this month's jobs (UTC), the quota and what is left.

## Batch names (needs a key)

```
curl -H "Authorization: Bearer $KEY" -F csv=@names.csv "https://stitch.temsor.com/v1/names/batch?width_mm=80&font=sans&formats=pes,dst" -o names.zip
```

Up to 60 names: a CSV in field `csv` (a `name` column, optional `surname` / `line 2` column) or field `names` with one
name per line (`Name | Surname` puts the surname on a second line). Query: `width_mm`, `font` (`sans`, `serif`, `slab`,
`script`), `fabric`, `color` (#rrggbb), `formats`. Returns a zip: one file per name per format plus `names.csv` with each
name's size, stitch count and quality status. Each name counts as one job against the key.


## MCP server

Agents that speak [Model Context Protocol](https://modelcontextprotocol.io) can use our `stitch_mcp` package instead of raw HTTP.
It wraps the same public API with tools: `list_presets`, `digitize_logo`, `job_status`, `download_design`, `get_usage`, `get_pricing`, `health_check`.

```
export STITCH_API_KEY=tsk_...
export STITCH_SITE_URL=https://stitch.temsor.com
python -m stitch_mcp                 # stdio (Cursor, Claude Desktop)
python -m stitch_mcp --http --port 8787   # Streamable HTTP at http://127.0.0.1:8787/mcp
```

Cursor `mcp.json` sketch: `{"mcpServers":{"temsor-stitch":{"command":"python","args":["-m","stitch_mcp"],"env":{"STITCH_API_KEY":"tsk_...","STITCH_SITE_URL":"https://stitch.temsor.com"}}}}`.
Human docs: https://stitch.temsor.com/api

## Limits and etiquette

One job at a time on a shared server; 120 jobs per hour per anonymous client (429 with `Retry-After` beyond); API keys have their own limits.
Errors are JSON `{"error": code, "message": text}`. Don't upload images the user doesn't have the right to use.
