{
  "openapi": "3.1.0",
  "info": {
    "title": "String Art API",
    "version": "1.0.0",
    "description": "Generate String Art App patterns: nail sequences, previews, printable templates and step-by-step PDFs. Docs: https://stringartapp.com/developers/ The free Sandbox is for testing only: its previews and PDFs are stamped \"SANDBOX\" and may not be used in production or sold.",
    "contact": {
      "email": "support@stringartapp.com"
    },
    "termsOfService": "https://stringartapp.com/terms/"
  },
  "servers": [
    {
      "url": "https://stringartapp.com/api/v1"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/patterns": {
      "post": {
        "operationId": "createPattern",
        "summary": "Create a pattern",
        "description": "Accepts the photo and settings, reserves one pattern from your plan, and answers right away with status queued. Failed patterns are not charged.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Sending the same key again returns the first pattern instead of making a new one."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Settings"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "image_url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Public https:// address of the photo."
                      },
                      "image_base64": {
                        "type": "string",
                        "description": "The photo, base64 (a data: URL prefix is allowed)."
                      },
                      "webhook_url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Growth and Business plans."
                      }
                    }
                  }
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "image"
                ],
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary"
                  },
                  "settings": {
                    "type": "string",
                    "description": "Settings as a JSON string."
                  },
                  "webhook_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted and queued.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pattern"
                }
              }
            }
          },
          "200": {
            "description": "Idempotent replay of an earlier request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pattern"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "get": {
        "operationId": "listPatterns",
        "summary": "List recent patterns (kept for 7 days)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Newest first, without results.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Pattern"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/patterns/{id}": {
      "get": {
        "operationId": "getPattern",
        "summary": "Get a pattern's status and results",
        "parameters": [
          {
            "$ref": "#/components/parameters/PatternId"
          }
        ],
        "responses": {
          "200": {
            "description": "The pattern.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Pattern"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/patterns/{id}/files/{path}": {
      "get": {
        "operationId": "getPatternFile",
        "summary": "Download a result file",
        "parameters": [
          {
            "$ref": "#/components/parameters/PatternId"
          },
          {
            "name": "path",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "A/preview.jpg",
                "A/sequence.pdf",
                "B/preview.jpg",
                "B/sequence.pdf",
                "C/preview.jpg",
                "C/sequence.pdf",
                "D/preview.jpg",
                "D/sequence.pdf",
                "template.pdf"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file.",
            "content": {
              "image/jpeg": {},
              "application/pdf": {}
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Plan and usage",
        "responses": {
          "200": {
            "description": "Your account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "webhooks": {
    "patternFinished": {
      "post": {
        "summary": "Sent when a pattern succeeds or fails (up to 3 tries).",
        "description": "Check the StringArt-Signature header: t=<unix time>,v1=<hex HMAC-SHA256 of t + '.' + body with your webhook signing secret>.",
        "parameters": [
          {
            "name": "StringArt-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "pattern.succeeded",
                      "pattern.failed"
                    ]
                  },
                  "pattern_id": {
                    "type": "string"
                  },
                  "created": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Any 2xx acknowledges the event."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your API key, sa_live_..."
      }
    },
    "parameters": {
      "PatternId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^pat_[A-Za-z0-9]{24}$"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Settings": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "shape": {
            "type": "string",
            "enum": [
              "circular",
              "rectangular"
            ],
            "default": "circular"
          },
          "color": {
            "type": "string",
            "enum": [
              "black",
              "white",
              "color",
              "black_white"
            ],
            "default": "black",
            "description": "black: black thread on a white board. white: white thread on a dark board. color: several colors (palette). black_white: black and white thread together on the board you choose (board)."
          },
          "board": {
            "type": "string",
            "enum": [
              "white",
              "black"
            ],
            "default": "white",
            "description": "black_white only: the board color the black and white threads go on."
          },
          "nails": {
            "type": "integer",
            "minimum": 120,
            "maximum": 350,
            "default": 220
          },
          "lines": {
            "type": "integer",
            "minimum": 1000,
            "maximum": 12000,
            "default": 3000,
            "description": "Defaults to 3000, 2000 for white thread, and 12000 for black_white (its solver stops by itself once more thread no longer helps, usually at 3,500 to 5,000 lines)."
          },
          "thread_thickness_mm": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 2.0,
            "multipleOf": 0.01,
            "default": 0.2
          },
          "diameter_cm": {
            "type": "number",
            "minimum": 20,
            "maximum": 200,
            "multipleOf": 0.1,
            "default": 60,
            "description": "Circular frames only."
          },
          "width_cm": {
            "type": "number",
            "minimum": 20,
            "maximum": 200,
            "multipleOf": 0.1,
            "default": 60,
            "description": "Rectangular frames only."
          },
          "height_cm": {
            "type": "number",
            "minimum": 20,
            "maximum": 200,
            "multipleOf": 0.1,
            "default": 60,
            "description": "Rectangular frames only."
          },
          "nail_diameter_mm": {
            "type": "number",
            "minimum": 0.5,
            "maximum": 6,
            "multipleOf": 0.1,
            "default": 2,
            "description": "Black and white thread. Nails plus thread must fit between neighbouring nails."
          },
          "algorithm": {
            "type": "string",
            "enum": [
              "A",
              "B",
              "C",
              "D",
              "all"
            ],
            "default": "all",
            "description": "Black and white thread, circular or rectangular. \"all\" returns all four of the app's algorithms, A to D (A is the newest). A letter returns only that one, which is ready sooner. Either way the request is 1 pattern."
          },
          "remove_background": {
            "type": "boolean",
            "default": true,
            "description": "Black and white thread. true puts the main subject on a plain backdrop, as the app does; false keeps the photo's background."
          },
          "nail_layout": {
            "type": "string",
            "enum": [
              "uniform",
              "ruler-v2"
            ],
            "default": "uniform",
            "description": "Rectangular black or white only."
          },
          "palette": {
            "type": "string",
            "enum": [
              "cmyk",
              "rgb",
              "custom"
            ],
            "default": "cmyk",
            "description": "Color patterns only."
          },
          "custom_colors": {
            "type": "array",
            "minItems": 2,
            "maxItems": 6,
            "items": {
              "type": "string",
              "pattern": "^#[0-9A-Fa-f]{6}$"
            },
            "description": "With palette custom."
          },
          "crop": {
            "type": "object",
            "required": [
              "x",
              "y",
              "width",
              "height"
            ],
            "description": "Fractions of the photo, 0 to 1. Without it the photo is centre-cropped to the frame.",
            "properties": {
              "x": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "y": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "width": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "height": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_settings",
                  "invalid_image",
                  "invalid_request",
                  "invalid_key",
                  "quota_exhausted",
                  "spend_cap_reached",
                  "webhooks_unavailable",
                  "idempotency_conflict",
                  "not_found",
                  "rate_limited",
                  "too_many_jobs",
                  "unavailable",
                  "server_error"
                ]
              },
              "message": {
                "type": "string"
              },
              "field": {
                "type": "string"
              }
            }
          }
        }
      },
      "Result": {
        "type": "object",
        "properties": {
          "algorithm": {
            "type": "string",
            "enum": [
              "A",
              "B",
              "C",
              "D"
            ],
            "description": "Circular black: the algorithm of this result, as in the app's tabs. Rectangular black or white: A or B. Other patterns: A."
          },
          "nails": {
            "type": "integer"
          },
          "lines": {
            "type": "integer"
          },
          "sequence": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1
            },
            "description": "lines + 1 nail numbers, starting at 1."
          },
          "wraps": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "cw",
                "ccw"
              ]
            },
            "description": "Circular black: wrap direction at each nail."
          },
          "thread_length_m": {
            "type": "number"
          },
          "background_removed": {
            "type": "boolean",
            "description": "Circular black: true when the main subject was found and put on a plain backdrop. false when remove_background is false or the photo has no clear subject."
          },
          "nail_positions_mm": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "number"
              },
              "minItems": 2,
              "maxItems": 2
            },
            "description": "x, y in millimetres from the frame centre, x to the right and y down."
          },
          "palette": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "hex": {
                  "type": "string"
                }
              }
            }
          },
          "line_colors": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Color patterns: the thread color of each line."
          },
          "strands": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "color": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "sequence": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            }
          },
          "color_changes": {
            "type": "integer"
          },
          "board": {
            "type": "string",
            "enum": [
              "white",
              "black"
            ],
            "description": "black_white patterns: the board color."
          }
        }
      },
      "Pattern": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "const": "pattern"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed"
            ]
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "settings": {
            "$ref": "#/components/schemas/Settings"
          },
          "billed_as": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "plan",
              "overage",
              "pack",
              "sandbox",
              null
            ]
          },
          "watermarked": {
            "type": "boolean",
            "description": "True for free Sandbox patterns: previews and PDFs are stamped \"SANDBOX\" (testing only)."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          },
          "results": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "$ref": "#/components/schemas/Result"
            }
          },
          "files": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "A": {
                "type": "object",
                "properties": {
                  "preview_jpg": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  },
                  "sequence_pdf": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "B": {
                "type": "object",
                "properties": {
                  "preview_jpg": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  },
                  "sequence_pdf": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "C": {
                "type": "object",
                "properties": {
                  "preview_jpg": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  },
                  "sequence_pdf": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "D": {
                "type": "object",
                "properties": {
                  "preview_jpg": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  },
                  "sequence_pdf": {
                    "type": "object",
                    "properties": {
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Download with your API key."
                      },
                      "signed_url": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "format": "uri",
                        "description": "Works without a key for one hour."
                      },
                      "signed_url_expires_in": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "template_pdf": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Download with your API key."
                  },
                  "signed_url": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uri",
                    "description": "Works without a key for one hour."
                  },
                  "signed_url_expires_in": {
                    "type": "integer"
                  }
                }
              }
            },
            "description": "One entry per result letter, plus the nail template."
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "object": {
            "const": "account"
          },
          "plan": {
            "type": "string",
            "enum": [
              "sandbox",
              "payg",
              "starter",
              "growth",
              "business",
              "enterprise"
            ]
          },
          "subscription_status": {
            "type": [
              "string",
              "null"
            ]
          },
          "period": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "start": {
                "type": "string"
              },
              "end": {
                "type": "string"
              },
              "used": {
                "type": "integer"
              },
              "included": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "sandbox": {
            "type": "object",
            "properties": {
              "used_this_month": {
                "type": "integer"
              },
              "free_per_month": {
                "type": "integer"
              }
            }
          },
          "pack_credits": {
            "type": "integer"
          },
          "monthly_cap": {
            "type": [
              "integer",
              "null"
            ]
          },
          "concurrent_patterns": {
            "type": "integer"
          },
          "webhooks": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
