Guide
Write handwriting
One request writes handwriting onto a set of lines. Loop on what's left to fill as many pages as you like.
Request
curl https://www.deepscribble.com/api/v1/handwriting \
-H "Authorization: Bearer $DEEPSCRIBBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Dear Sam,\nThank you for the flowers. They made my whole week!",
"regions": [
{
"x": 40,
"y": 84,
"width": 520,
"height": 44
},
{
"x": 40,
"y": 148,
"width": 520,
"height": 44
},
{
"x": 40,
"y": 212,
"width": 520,
"height": 44
}
]
}'Response
{
"id": "req_67f48ae3e0b9453ab634e486f6ca485e",
"object": "handwriting",
"created": 1796481762,
"style": "9d914b41-0358-49eb-9e2c-bfdb06163b60",
"width": 560,
"height": 214,
"lines": [
{
"region": 0,
"text": "Dear Sam,",
"bbox": [47.663, 56.069, 112.795, 32.584]
},
{
"region": 1,
"text": "Thank you for the flowers. They made my",
"bbox": [47.494, 116.854, 463.002, 48.963]
},
{
"region": 2,
"text": "whole week!",
"bbox": [47.494, 184.54, 124.119, 28.817]
}
],
"regions_used": 3,
"remaining_text": "",
"done": true,
"substitutions": [],
"usage": { "characters": 59, "cost": "0.118", "currency": "INR" },
"balance": { "amount": "1.882", "currency": "INR" },
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 560 214\" width=\"560\" height=\"214\">…</svg>"
}How text fills your regions
- A region is one line of writing.
xandymark where the line starts,widthruns along it, andheightis the room for letters above it. Descenders hang below, just like on ruled paper. - Regions fill in the order you send them. A long line carries on into the next region, and words always stay whole.
- A new line in your text starts the next region. A blank line leaves a region empty, which is handy for paragraph gaps.
- Use any unit; the response comes back in the same one.
What each setting changes
x, yregionwidthregionheightregionrotationregionink.thicknessinkstylewritinglegibilitywritingRequest
textstring · requiredregionsarray · required{ x, y, width, height, rotation? } with x, y at the start of the line. rotation is in degrees, clockwise around that start.stylestringid from GET /v1/styles. Defaults to the first style in the catalog.ink.colorstring#2563eb.ink.thicknessnumberink.finishstringink (default), glitter, foil or holo.legibilitynumbercanvasobject{ width, height }for the SVG's viewBox, usually your page size. Defaults to the area your regions cover.formatstringsvg (default) returns one SVG document. paths returns an outline per line for your own renderer, PDF library or plotter.dry_runbooleanResponse
svgstringlinesarraybbox of [x, y, width, height]. With format: "paths", each line also has a path to fill with the top-level fill colour.regions_usednumberremaining_textstringdone is true.substitutionsarray{ "from": "é", "to": "e" }.usageobjectbalanceobjectFilling whole pages
One request writes up to 800 characters (400 with glitter). Keep going with the regions you haven't used yet plus remaining_text, and start a fresh set of regions when a page is full. Every SVG shares your page's coordinates, so the pieces of one page layer cleanly.
async function write(body) {
const res = await fetch("https://www.deepscribble.com/api/v1/handwriting", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DEEPSCRIBBLE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
if (!res.ok) throw new Error((await res.json()).error.message);
return res.json();
}
// ruledLines() returns the regions of one fresh page.
let text = letter;
let page = 0;
let regions = ruledLines();
const layers = []; // [page, svg]
while (text) {
const res = await write({ text, regions, style: STYLE_ID });
layers.push([page, res.svg]);
text = res.remaining_text;
regions = regions.slice(res.regions_used);
if (regions.length === 0) {
page += 1;
regions = ruledLines();
}
}Check the fit first
Add "dry_run": trueto see which text lands in which region, what's left over, and the price, before you spend anything.
Request
curl https://www.deepscribble.com/api/v1/handwriting \
-H "Authorization: Bearer $DEEPSCRIBBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Dear Sam,\nThank you for the flowers. They made my whole week!",
"regions": [
{
"x": 40,
"y": 84,
"width": 520,
"height": 44
},
{
"x": 40,
"y": 148,
"width": 520,
"height": 44
},
{
"x": 40,
"y": 212,
"width": 520,
"height": 44
}
],
"dry_run": true
}'Response
{
"id": "req_5c0e9d2f8a1b4c6e9f7a3b2d1c0e8f6a",
"object": "handwriting",
"created": 1796481700,
"style": "9d914b41-0358-49eb-9e2c-bfdb06163b60",
"dry_run": true,
"lines": [
{ "region": 0, "text": "Dear Sam," },
{ "region": 1, "text": "Thank you for the flowers. They made my" },
{ "region": 2, "text": "whole week!" }
],
"regions_used": 3,
"remaining_text": "",
"done": true,
"substitutions": [],
"usage": { "characters": 0, "cost": "0.000", "currency": "INR" },
"balance": { "amount": "2.000", "currency": "INR" },
"estimate": { "characters": 59, "cost": "0.118", "currency": "INR" }
}Characters
Handwriting covers English letters, digits and common punctuation. Other characters are swapped for a close match, so é becomes e and & becomes and, and every swap is listed in substitutions. Each region writes up to 100 characters.
id, or request_id on errors), also sent as the x-request-idheader. It's the fastest way for us to help if something looks off.