<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PerfectVector</title>
    <description>The latest articles on DEV Community by PerfectVector (@perfectvector).</description>
    <link>https://dev.to/perfectvector</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4223682%2Ff84af727-bfc2-43b4-a0da-88b34e3c44eb.png</url>
      <title>DEV Community: PerfectVector</title>
      <link>https://dev.to/perfectvector</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/perfectvector"/>
    <language>en</language>
    <item>
      <title>Making Our API Docs Available as Markdown for Coding Agents (llms.txt, Accept Headers)</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Fri, 20 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/making-our-api-docs-available-as-markdown-for-coding-agents-llmstxt-accept-headers-55o4</link>
      <guid>https://dev.to/perfectvector/making-our-api-docs-available-as-markdown-for-coding-agents-llmstxt-accept-headers-55o4</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An HTML documentation page can carry far more than its documentation text. We checked what our own "API for AI agents" page sends when you fetch it, and what we publish alongside it. All numbers are from 2026-11-13. They measure response sizes, not model tokens, cost or whether an agent does better with them; we haven't tested that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What a plain fetch returns.&lt;/strong&gt; The page requested as HTML: 370,609 bytes. By a simple regex for &lt;code&gt;&amp;lt;script&amp;gt;…&amp;lt;/script&amp;gt;&lt;/code&gt; blocks, about 308,600 of those bytes are script tags (the framework's data payload; the exact figure shifts slightly between fetches). The visible text is about 11,600 characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we publish instead.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A Markdown twin of each doc page&lt;/strong&gt; (listed in a catalog). The same page at &lt;code&gt;/docs/api/agents.md&lt;/code&gt; is 12,290 bytes and has the endpoint table, errors and a full example. In this recording the HTML response was 30.2 times the size of the Markdown one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content negotiation.&lt;/strong&gt; The HTML URL answers &lt;code&gt;Accept: text/markdown&lt;/code&gt; with &lt;code&gt;Content-Type: text/markdown&lt;/code&gt;, so a client doesn't need to know the &lt;code&gt;.md&lt;/code&gt; convention:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  curl -s -H &lt;span class="s2"&gt;"Accept: text/markdown"&lt;/span&gt; https://perfectvector.com/docs/api/agents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/llms.txt&lt;/code&gt;&lt;/strong&gt;, 3,950 bytes: one sentence on what the product is, then links to the Markdown versions of the product facts, pricing, API reference and MCP docs. The HTML pages advertise it with &lt;code&gt;Link: &amp;lt;/llms.txt&amp;gt;; rel="describedby"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;/llms-full.txt&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;/docs/catalog.json&lt;/code&gt;&lt;/strong&gt;: a list of every documentation page with its summary, and a machine-readable catalog of published documents with versions and review dates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A page written for agents.&lt;/strong&gt; The agents page puts keys, endpoints, prices, limits, errors and a runnable example in one document, so the information for a first integration is in one document.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Writing choices beyond the format&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tables for anything a client will branch on: endpoints, status codes, retry rules.&lt;/li&gt;
&lt;li&gt;Stable error &lt;code&gt;code&lt;/code&gt; values documented as the thing to branch on, with &lt;code&gt;detail&lt;/code&gt; called out as not for parsing.&lt;/li&gt;
&lt;li&gt;Document versions and review dates exposed in the catalog.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What we're not sure about.&lt;/strong&gt; We haven't verified which crawlers or agents fetch &lt;code&gt;llms.txt&lt;/code&gt;, the Markdown twins or the &lt;code&gt;Accept&lt;/code&gt; negotiation. Server logs could show requests for these files, but wouldn't by themselves show how an agent used them. We publish them anyway; any effect on agent accuracy remains untested.&lt;/p&gt;

&lt;p&gt;To try this on your own docs, start by checking what a plain &lt;code&gt;curl&lt;/code&gt; of your docs page returns, and how much of it is script.&lt;/p&gt;

&lt;p&gt;Docs for agents: &lt;a href="https://perfectvector.com/docs/api/agents?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=llms-docs&amp;amp;utm_content=dev-20261113-llms-docs" rel="noopener noreferrer"&gt;PerfectVector API for AI agents&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>documentation</category>
      <category>llm</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Failure Is Free: Designing an Image API So Agents Can Retry Safely</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Thu, 19 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/failure-is-free-designing-an-image-api-so-agents-can-retry-safely-1c7i</link>
      <guid>https://dev.to/perfectvector/failure-is-free-designing-an-image-api-so-agents-can-retry-safely-1c7i</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When an AI agent calls a paid API, it will retry. Timeouts, dropped connections and restarted tool loops all produce duplicate requests, and a duplicate that charges twice is the bug people remember. This post is about the contract: what an API should promise on a retry, a conflict and a failure. The examples are real responses from the PerfectVector Developer API, recorded with a test key on 2026-11-13. (For client code that uses these rules, see the Python post earlier this week.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rule: one key, one conversion.&lt;/strong&gt; &lt;code&gt;POST /v1/vectorizations&lt;/code&gt; takes an &lt;code&gt;Idempotency-Key&lt;/code&gt; (8–128 characters: letters, digits, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt;). The same key with the same image bytes returns the original conversion in its current state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;POST&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;v1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;vectorizations&lt;/span&gt;  &lt;span class="nc"&gt;Idempotency&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;devto&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;wed&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;001&lt;/span&gt;  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt;×&lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="no"&gt;PNG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
→ &lt;span class="mi"&gt;201&lt;/span&gt;   &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;credits&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;charged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;   &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;credits&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;would&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="nc"&gt;Same&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;same&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;again&lt;/span&gt;
→ &lt;span class="mi"&gt;201&lt;/span&gt;   &lt;span class="n"&gt;idempotent&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;replayed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;   &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;credits&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;charged&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;   &lt;span class="n"&gt;same&lt;/span&gt; &lt;span class="n"&gt;vec_&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reusing a key for a different request is refused.&lt;/strong&gt; We sent the same key with a different, valid 300×200 image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;→ 409 idempotency_conflict
  "This Idempotency-Key was used for a different request (another image or other options). Send a new key."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing is created or charged. The docs say "same request" means the same image bytes and options; the file name and the &lt;code&gt;Prefer&lt;/code&gt; and &lt;code&gt;Accept&lt;/code&gt; headers don't count.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What an error does to a key.&lt;/strong&gt; The docs say a request refused with a &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;402&lt;/code&gt;, &lt;code&gt;413&lt;/code&gt;, &lt;code&gt;415&lt;/code&gt;, &lt;code&gt;422&lt;/code&gt;, &lt;code&gt;429&lt;/code&gt; or &lt;code&gt;503&lt;/code&gt; doesn't tie the key to anything: fix the request and retry with the same key. In one recorded case we sent the already-used key with a 64×64 image and got &lt;code&gt;422 invalid_image&lt;/code&gt;, not a &lt;code&gt;409&lt;/code&gt;, and a fresh key with the same small image got the same &lt;code&gt;422&lt;/code&gt;. We can't say from that one case what the server's full order of checks is. The practical rule is the documented one: a rejected request leaves the key unused, but a key that already produced a conversion stays bound to that conversion's image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure is free.&lt;/strong&gt; A failed conversion is not an HTTP error. It answers &lt;code&gt;201&lt;/code&gt; with &lt;code&gt;"status": "failed"&lt;/code&gt; and charges nothing, and a replayed failure stays failed, so a retry needs a new key. A live key is charged 1 credit only when a conversion succeeds. Status checks and repeat downloads cost nothing.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What happened&lt;/th&gt;
&lt;th&gt;Retry with&lt;/th&gt;
&lt;th&gt;Charge for that attempt&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Timeout or dropped connection&lt;/td&gt;
&lt;td&gt;the same key&lt;/td&gt;
&lt;td&gt;at most once, on success&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;409 idempotency_conflict&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;a new key&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;422&lt;/code&gt;, &lt;code&gt;413&lt;/code&gt;, &lt;code&gt;415&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;the same key, after fixing the request&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;201&lt;/code&gt; with &lt;code&gt;status: failed&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;a new key&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;429&lt;/code&gt; / &lt;code&gt;503&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;the same key, after &lt;code&gt;Retry-After&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;500&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the same key&lt;/td&gt;
&lt;td&gt;at most once, on success&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The "charge" column is about the attempt that failed or was refused. A corrected or new-key request that succeeds on a live key costs 1 credit, like any conversion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What to copy into your own API&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make the key part of the contract and say which parts of a request count as "the same".&lt;/li&gt;
&lt;li&gt;Return the original conversion in its current state on a replay and flag ordinary replays with a header. Document the exceptions: two identical requests that arrive at the same time get the same conversion, and the second answer may not carry the replay header.&lt;/li&gt;
&lt;li&gt;Say what an error does to the key.&lt;/li&gt;
&lt;li&gt;Make "failed" a normal response with a status field, and don't charge for it.&lt;/li&gt;
&lt;li&gt;Publish a retry table that makes each condition and its next action explicit.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keys live for 24 hours. Without the header, the API still works, but every request is a new conversion, so a retry after a timeout can convert, and charge, the same image twice.&lt;/p&gt;

&lt;p&gt;Docs: &lt;a href="https://perfectvector.com/docs/api/idempotency?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=api-retry&amp;amp;utm_content=dev-20261113-api-retry" rel="noopener noreferrer"&gt;Idempotency&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>design</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
    <item>
      <title>Calling an Image-to-SVG API From Python: Test Keys, Retries, Polling and Errors</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/calling-an-image-to-svg-api-from-python-test-keys-retries-polling-and-errors-56dm</link>
      <guid>https://dev.to/perfectvector/calling-an-image-to-svg-api-from-python-test-keys-retries-polling-and-errors-56dm</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A script that calls a conversion API needs more than the happy path. It has to survive a dropped connection without converting twice, cope with error responses that aren't what you expected, and stop waiting at some point. Here is a single-image Python example that does all three, run against the PerfectVector Developer API with a test key. Test keys return a fixed sample SVG, so the run needed no credits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.perfectvector.com/v1"&lt;/span&gt;
&lt;span class="no"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {os.environ['PERFECTVECTOR_API_KEY']}"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OutOfTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;OutOfTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"not enough time budget left to wait"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;OutOfTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"time budget used up"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;130&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;left&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# the API may wait up to 120 s&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                  &lt;span class="c1"&gt;# API errors: application/problem+json&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{r.status_code} {p['code']}: {p['detail']}"&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;                                 &lt;span class="c1"&gt;# the network edge can answer with HTML&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{r.status_code}, not an API error body"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_wait&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Derived from the file bytes: a retry of the same file reuses the conversion.&lt;/span&gt;
    &lt;span class="c1"&gt;# Pass key="..." for an intentional new conversion of the same bytes.&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;"img-"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;deadline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;monotonic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;max_wait&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"POST"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API}/vectorizations"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                         &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Idempotency-Key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accept"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"image/svg+xml"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                         &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestException&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"network error:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="nf"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"image/svg+xml"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"wb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"saved {out} ({len(r.content)} bytes), charged={r.headers.get('X-Credits-Charged', '?')}, replayed={r.headers.get('Idempotent-Replayed', 'false')}"&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;wait&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Retry-After"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Retry-After"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isdigit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
                    &lt;span class="nf"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                              &lt;span class="c1"&gt;# 201 or 202: a vectorization object&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"queued"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"processing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="nf"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API}/vectorizations/{v['id']}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"succeeded"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"failed: {v['results'][0]['error']['code']} (not charged)"&lt;/span&gt;
            &lt;span class="n"&gt;svg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"results"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"wb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"saved {out} ({len(svg.content)} bytes) from the result URL"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"gave up after 3 attempts"&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;OutOfTime&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{e}; the conversion may still finish, so look it up by Idempotency-Key later"&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;KeyError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IndexError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"unexpected API response shape; check the docs for this API version"&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RequestException&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"network error: {e}"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What it does, and why each piece is there:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The key comes from the file.&lt;/strong&gt; &lt;code&gt;Idempotency-Key&lt;/code&gt; is a hash of the image bytes, so a retry of the same file reuses the first conversion for as long as the API keeps the key (24 hours, per the docs). The flip side: converting the same bytes again on purpose inside that window returns the old conversion, so the function takes an explicit &lt;code&gt;key=&lt;/code&gt; for a deliberate redo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One time budget.&lt;/strong&gt; &lt;code&gt;max_wait&lt;/code&gt; becomes a deadline. Every request checks it first and gets a timeout capped by what's left, and every wait (back-off, &lt;code&gt;Retry-After&lt;/code&gt;, polling) is skipped, with a clear message, if it wouldn't fit. A &lt;code&gt;Retry-After&lt;/code&gt; longer than the budget ends the call instead of sleeping. If time runs out, the conversion may still finish on the server, so the message says to look it up by its &lt;code&gt;Idempotency-Key&lt;/code&gt; later. Two limits to know: &lt;code&gt;requests&lt;/code&gt;' timeout bounds each connect and read, not the total elapsed time of a slow response, so for a hard wall-clock limit run the call in a thread or process you can abandon; and an SVG body that arrives just after the deadline is still saved, while a late JSON success is not followed by a download request. The docs also warn that &lt;code&gt;requests&lt;/code&gt; has no default timeout and HTTPX's default is short, so set one for this endpoint either way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branching on status and &lt;code&gt;Content-Type&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;201&lt;/code&gt; with &lt;code&gt;image/svg+xml&lt;/code&gt; is the file. Any other &lt;code&gt;201&lt;/code&gt; or &lt;code&gt;202&lt;/code&gt; carries a vectorization object, so the code reads its &lt;code&gt;status&lt;/code&gt; instead of assuming: a &lt;code&gt;201&lt;/code&gt; can be a finished conversion without the SVG attached, or a failed one (not charged). &lt;code&gt;queued&lt;/code&gt; and &lt;code&gt;processing&lt;/code&gt; are polled every 2 seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Errors without crashing.&lt;/strong&gt; API errors come as &lt;code&gt;application/problem+json&lt;/code&gt; with a stable &lt;code&gt;code&lt;/code&gt;; &lt;code&gt;429&lt;/code&gt; and &lt;code&gt;503&lt;/code&gt; are retried after &lt;code&gt;Retry-After&lt;/code&gt;. Responses from the network edge can be non-JSON (the docs say so for some &lt;code&gt;403&lt;/code&gt; and &lt;code&gt;429&lt;/code&gt;), so &lt;code&gt;describe()&lt;/code&gt; falls back to the status code. The follow-up status and download calls get the same checks, and a response with an unexpected shape (missing fields, empty &lt;code&gt;results&lt;/code&gt;, a non-JSON &lt;code&gt;201&lt;/code&gt;) returns a clear message instead of a traceback.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What we ran (test key, 2026-11-13, Python 3.9, &lt;code&gt;requests&lt;/code&gt; 2.32.5):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Case&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A new 320×240 PNG, first call&lt;/td&gt;
&lt;td&gt;saved 713 bytes, charged=0, replayed=false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The same file again&lt;/td&gt;
&lt;td&gt;saved 713 bytes, charged=0, replayed=true&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The same bytes with an explicit new key (a separate run)&lt;/td&gt;
&lt;td&gt;saved 713 bytes, charged=0, replayed=false&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A 64×64 PNG&lt;/td&gt;
&lt;td&gt;&lt;code&gt;422 invalid_image: Each image dimension must be between 100 and 4096 pixels&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A wrong key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;401 invalid_api_key&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The three saved files were byte-identical. The 713 bytes are the test-mode sample file, which is the same for every image, so this run checks the request flow, not trace quality. Test mode answers instantly and never returns &lt;code&gt;202&lt;/code&gt;, so we exercised the other branches with mocked responses and a fake clock (17 cases): three request timeouts, &lt;code&gt;Retry-After: 3600&lt;/code&gt;, &lt;code&gt;Retry-After: 2&lt;/code&gt; three times and a date-format &lt;code&gt;Retry-After&lt;/code&gt;, an HTML &lt;code&gt;403&lt;/code&gt;, a &lt;code&gt;202&lt;/code&gt; that goes processing → succeeded → download, a conversion that never finishes (budgets of 20 s and 3 s), an HTTP &lt;code&gt;500&lt;/code&gt; on the status call, a failed conversion, &lt;code&gt;201&lt;/code&gt; bodies with missing fields, empty &lt;code&gt;results&lt;/code&gt;, a &lt;code&gt;null&lt;/code&gt; result and no JSON at all, and responses that arrive at 301 s against a 300 s budget. In 15 of the 17 the code stopped at or before the budget (300 of 300 s for three timeouts, 20 of 20 s, 2 of 3 s). In the two where the response itself landed at 301 s, the late JSON success ended with a "time budget used up" message and no download request, and the late SVG body was saved. Every unusual response ended with a message instead of a traceback.&lt;/p&gt;

&lt;p&gt;One limit to plan around: by default an account runs one live conversion at a time, across all its keys. A second request is refused rather than queued, normally with &lt;code&gt;429 too_many_in_flight&lt;/code&gt;, or with &lt;code&gt;402 insufficient_credits&lt;/code&gt; when the available balance covers only the running conversion. Run a batch one image after another instead of in parallel. We haven't run live conversions for this post.&lt;/p&gt;

&lt;p&gt;Docs: &lt;a href="https://perfectvector.com/docs/api/quickstart?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=api-python&amp;amp;utm_content=dev-20261113-api-python" rel="noopener noreferrer"&gt;Quickstart&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>tutorial</category>
      <category>svg</category>
    </item>
    <item>
      <title>Writing an MCP Tool That Returns Files: the 24-Hour Download-Link Pattern</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/writing-an-mcp-tool-that-returns-files-the-24-hour-download-link-pattern-58b9</link>
      <guid>https://dev.to/perfectvector/writing-an-mcp-tool-that-returns-files-the-24-hour-download-link-pattern-58b9</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An MCP tool that produces a file needs a clear delivery contract: how the user retrieves the file, how long access lasts, and who can use the link. We build an image-to-SVG MCP server, and its public docs describe such a contract. Below are seven rules from it, each with the behavior the docs state as of 2026-11-13. Everything here is client-visible behavior from the docs, not a description of our server's internals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Return a reference with an expiry, not the file.&lt;/strong&gt; The delivered SVG comes back as a download link that works for 24 hours. While the SVG is still stored, an expired link can be replaced for free; once it's gone, the tool says it's unavailable and doesn't start a new paid conversion. The file itself is kept for about 30 days after upload.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Remember the link is a bearer secret.&lt;/strong&gt; Anyone with the link can download that SVG until it expires, and it keeps working after you disconnect the assistant, unless the PerfectVector account is deleted first. The docs say so in plain words ("share it only as you would share the file"). If your tool does the same, say it where users will read it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Let the assistant read small results.&lt;/strong&gt; The assistant can read a delivered SVG's text to keep working with it (recolor it, animate it, embed it), up to about 2 MB. Larger files are download-only. For your own tool, document the inline-read limit and the download fallback.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Make input flexible, because chat clients differ.&lt;/strong&gt; The same tool accepts an image four ways: a public &lt;code&gt;https://&lt;/code&gt; link to the image file itself (fetched without your cookies), an attachment in ChatGPT, a file chosen in a card inside Claude, and a local path an agent such as Claude Code can upload itself. Limits apply to all four: PNG, JPEG or WebP, up to 5 MB, 100–4,096 px per side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Put a free price check before the paid step.&lt;/strong&gt; The tool prices the request first (free), and conversion needs authorization first: an answer in the chat, a permission you grant in the app, or choosing a file in the card. If you've set an app to always allow the step, it can start without a new prompt. If nobody answers within 30 minutes, the request expires, the uploaded image is deleted, and no credit is used. Whether the question comes from the assistant or the client's permission dialog depends on the client; the docs list which defaults each one uses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Make re-fetching safe.&lt;/strong&gt; "Get my last SVG" returns the file already made. It does not start a new paid request, and continuing a conversion that is still processing never charges twice. A new request for the same image is a new request, and it is charged again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Say what you can't do.&lt;/strong&gt; The tool converts with standard settings and has no controls for detail, colors or background removal. If you want a different result, edit the image first. Documenting the limit also keeps the assistant from promising knobs that don't exist.&lt;/p&gt;

&lt;p&gt;None of this is specific to SVGs. Any tool that takes a file and returns a file can reuse the seven: an expiring reference, a stated sharing model, an inline-read limit, several input paths, a free price check before a paid step, a re-fetch that doesn't start new work, and documented limits.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://perfectvector.com/docs/mcp/credits-delivery?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=mcp-file-links&amp;amp;utm_content=dev-20261113-mcp-file-links" rel="noopener noreferrer"&gt;PerfectVector MCP credits and downloads&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Is That .svg Real? A 20-Line Check for Agent-Made SVGs</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/is-that-svg-real-a-20-line-check-for-agent-made-svgs-3ekn</link>
      <guid>https://dev.to/perfectvector/is-that-svg-real-a-20-line-check-for-agent-made-svgs-3ekn</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A file ending in &lt;code&gt;.svg&lt;/code&gt; is not necessarily vector art. Some tools wrap a bitmap in an &lt;code&gt;&amp;lt;svg&amp;gt;&lt;/code&gt; element: the file opens in a browser, scales without errors, and you can't edit a single shape, because there are none. If an AI agent hands you an SVG, check what's inside before you send it to a cutter, a print shop or a design tool.&lt;/p&gt;

&lt;p&gt;Here's a check that needs only Python's standard library. It counts shape elements and path commands, and flags &lt;code&gt;&amp;lt;image&amp;gt;&lt;/code&gt; elements whose reference is a &lt;code&gt;data:image/&lt;/code&gt; URI or a common raster filename (&lt;code&gt;.png&lt;/code&gt;, &lt;code&gt;.jpg&lt;/code&gt;, &lt;code&gt;.webp&lt;/code&gt;, &lt;code&gt;.gif&lt;/code&gt;). It's a heuristic, not proof that a file is vector-only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;etree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ElementTree&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="no"&gt;ET&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;audit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;ET&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getroot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;tags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'}'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;shapes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'rect'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'circle'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ellipse'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'polygon'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'polyline'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'line'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;raster&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'}'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'image'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;href&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'href'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'{http://www.w3.org/1999/xlink}href'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'data:image/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'\.(png|jpe?g|webp|gif)(\?|$)'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;I&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;raster&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;cmds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'[MmLlHhVvCcSsQqTtAaZz]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'}'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;verdict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'FAKE (bitmap inside)'&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;raster&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;shapes&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MIXED'&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;raster&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s1"&gt;'vector'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'shapes'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'path_commands'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cmds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'raster_images'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;raster&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'verdict'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;audit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We ran it on three files we built for this test. &lt;code&gt;fake.svg&lt;/code&gt; is a 256×256 PNG (1,682 bytes) base64-embedded in an &lt;code&gt;&amp;lt;image&amp;gt;&lt;/code&gt; tag, 2,449 bytes in total. &lt;code&gt;handcoded.svg&lt;/code&gt; is a &lt;code&gt;&amp;lt;rect&amp;gt;&lt;/code&gt; and a &lt;code&gt;&amp;lt;circle&amp;gt;&lt;/code&gt;. The third is the fixed sample SVG that a PerfectVector API test key returns, which we used as a ready-made file with real paths.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;shapes&lt;/th&gt;
&lt;th&gt;path commands&lt;/th&gt;
&lt;th&gt;raster images&lt;/th&gt;
&lt;th&gt;verdict&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fake.svg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;FAKE (bitmap inside)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;handcoded.svg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;vector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API test sample&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;vector&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As a second opinion, &lt;code&gt;svgpathtools&lt;/code&gt;' &lt;code&gt;svg2paths&lt;/code&gt; (which turns basic shapes into paths) found 0, 2 and 5 paths in the same files, matching our shape counts.&lt;/p&gt;

&lt;p&gt;What this doesn't catch: &lt;code&gt;&amp;lt;image&amp;gt;&lt;/code&gt; references without a raster extension, shapes pulled in with &lt;code&gt;&amp;lt;use&amp;gt;&lt;/code&gt; from another file, bitmaps referenced from CSS (&lt;code&gt;background-image&lt;/code&gt;), or a real vector that is a bad trace (thousands of tiny paths). It can also flag a vector &lt;code&gt;data:image/svg+xml&lt;/code&gt; reference as a bitmap, and an empty SVG gets the "vector" label, because the script doesn't check visible artwork or editability. A real SVG can still be useless for cutting. Count nodes, too. So "vector" in the verdict only means "no bitmap found".&lt;/p&gt;

&lt;p&gt;Where does a real vector come from? For simple geometry, an agent can write the shapes itself, and the audit passes. For a photo or a detailed logo, it needs a tracer. If you give your agent a tracing tool, for example through MCP, run this check on whatever comes back, whoever made the tool. We made the same point about a model writing SVG code versus tracing an image in an earlier post: &lt;a href="https://dev.to/perfectvector/claude-can-write-svg-that-doesnt-mean-it-vectorized-your-png-2ib5"&gt;Claude Can Write SVG. That Doesn't Mean It Vectorized Your PNG&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The longer, no-code version of this check (editor selection, embedded vs linked images, what to do next): &lt;a href="https://perfectvector.com/blog/svg-contains-raster-image?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=svg-contains-raster-image&amp;amp;utm_content=dev-20261113-svg-real-check" rel="noopener noreferrer"&gt;How to Tell If an SVG Contains a Raster Image&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>svg</category>
      <category>python</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SVGO Deleted the ID My CSS Needed (and the One-Line Fix)</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Wed, 11 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/svgo-deleted-the-id-my-css-needed-and-the-one-line-fix-58lc</link>
      <guid>https://dev.to/perfectvector/svgo-deleted-the-id-my-css-needed-and-the-one-line-fix-58lc</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;SVGO made our badge almost 40% smaller and broke the page it lived on. The file still rendered fine on its own. What disappeared was an &lt;code&gt;id&lt;/code&gt; the surrounding HTML used to recolor one shape, and nothing in SVGO's output warns you about that. If your page, script or sprite reaches &lt;em&gt;into&lt;/em&gt; an SVG, run the optimizer on a copy and test the copy where it's actually used.&lt;/p&gt;

&lt;p&gt;Here's the fixture: a 437-byte hand-made badge whose sun is &lt;code&gt;&amp;lt;circle id="badge-accent" ... fill="#ef8067"/&amp;gt;&lt;/code&gt;, inlined in a page with &lt;code&gt;#badge-accent { fill: #f5bf42; }&lt;/code&gt; outside the SVG. With SVGO 4.1.0 in a clean folder (so no stray &lt;code&gt;svgo.config.mjs&lt;/code&gt; is picked up), &lt;code&gt;npx svgo input.svg -o default.svg&lt;/code&gt; writes 263 bytes, and the &lt;code&gt;id&lt;/code&gt; is gone. The sun stays coral instead of turning gold. That's documented behaviour: &lt;a href="https://svgo.dev/docs/plugins/cleanupIds/" rel="noopener noreferrer"&gt;cleanupIds&lt;/a&gt; "removes unused IDs", and an ID referenced only by CSS in &lt;em&gt;another&lt;/em&gt; document looks unused from inside the file. (Its back-off for &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; only applies when those elements are inside the SVG itself.)&lt;/p&gt;

&lt;p&gt;If you can name the hooks, keep the rest of the preset and protect just those IDs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// svgo.config.mjs&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;preset-default&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;overrides&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;cleanupIds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;preserve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;badge-accent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx svgo input.svg &lt;span class="nt"&gt;--config&lt;/span&gt; svgo.config.mjs &lt;span class="nt"&gt;-o&lt;/span&gt; preserved.svg
&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; input.svg default.svg preserved.svg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We re-ran it on 2026-11-04 and read the computed fill of the inlined circle in headless Chrome:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;File&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;#badge-accent&lt;/code&gt; present&lt;/th&gt;
&lt;th&gt;Computed fill&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Original&lt;/td&gt;
&lt;td&gt;437&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;rgb(245, 191, 66)&lt;/code&gt; gold&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Default preset&lt;/td&gt;
&lt;td&gt;263&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;rgb(239, 128, 103)&lt;/code&gt; coral&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;preserve: ['badge-accent']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;281&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;rgb(245, 191, 66)&lt;/code&gt; gold&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Keeping the hook cost 18 bytes. Turning &lt;code&gt;cleanupIds&lt;/code&gt; off entirely (&lt;code&gt;cleanupIds: false&lt;/code&gt;) gave the same 281 bytes here, but &lt;code&gt;preserve&lt;/code&gt; (or &lt;code&gt;preservePrefixes&lt;/code&gt; for a naming scheme like &lt;code&gt;icon-&lt;/code&gt;) still cleans IDs you didn't ask for, which helps once several SVGs are inlined on one page. These numbers are for this one fixture. Your byte counts will differ.&lt;/p&gt;

&lt;p&gt;An ID is only one kind of dependency, though. After any optimizer run (SVGO directly, or one your bundler runs for you later), check what consumes the file: CSS selectors, JS queries, gradient, clip and mask references, sprite &lt;code&gt;&amp;lt;symbol&amp;gt;&lt;/code&gt; IDs, and the &lt;code&gt;viewBox&lt;/code&gt; your layout scales with. Then test every state that touches it, like hover, theme and animation, because a static preview won't exercise them. And keep the unoptimized master: SVGO is for delivery copies, not the file someone will edit next.&lt;/p&gt;

&lt;p&gt;The full guide includes the copy-paste fixture, a dependency checklist table, notes on numeric precision, &lt;code&gt;viewBox&lt;/code&gt; and SVGZ, and an FAQ: &lt;strong&gt;&lt;a href="https://perfectvector.com/blog/svgo-optimize-svg?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=svgo-optimize-svg&amp;amp;utm_content=dev-20261104-svgo-optimize" rel="noopener noreferrer"&gt;SVGO: Optimize an SVG Without Losing Needed Structure&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>svg</category>
      <category>webdev</category>
      <category>css</category>
      <category>performance</category>
    </item>
    <item>
      <title>PNG to Android VectorDrawable: The Fill Rule That Eats Your Icon's Hole</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Tue, 10 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/png-to-android-vectordrawable-the-fill-rule-that-eats-your-icons-hole-f5o</link>
      <guid>https://dev.to/perfectvector/png-to-android-vectordrawable-the-fill-rule-that-eats-your-icons-hole-f5o</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Android Studio won't trace a PNG. Vector Asset Studio imports a &lt;strong&gt;Local file (SVG, PSD)&lt;/strong&gt; and turns supported geometry into VectorDrawable XML (&lt;a href="https://developer.android.com/studio/write/vector-asset-studio?hl=en" rel="noopener noreferrer"&gt;Android Developers&lt;/a&gt;). So a PNG icon takes two conversions: trace the pixels into a real SVG, then import that SVG. Each step can quietly change your icon, and the SVG in the middle is the cheapest place to catch it. Before importing, confirm the file is actually paths: an SVG can wrap a bitmap in an &lt;code&gt;&amp;lt;image&amp;gt;&lt;/code&gt; element, and that won't become a vector drawable.&lt;/p&gt;

&lt;p&gt;The mapping from SVG to VectorDrawable is close but not one-to-one. Here's a 24 dp ring icon, written both ways:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- ring.svg --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 24 24"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#1D9B5F"&lt;/span&gt; &lt;span class="na"&gt;fill-rule=&lt;/span&gt;&lt;span class="s"&gt;"evenodd"&lt;/span&gt;
        &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20zM12 7a5 5 0 1 0 0 10a5 5 0 1 0 0-10z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- res/drawable/ic_ring.xml --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;vector&lt;/span&gt; &lt;span class="na"&gt;xmlns:android=&lt;/span&gt;&lt;span class="s"&gt;"http://schemas.android.com/apk/res/android"&lt;/span&gt;
    &lt;span class="na"&gt;android:width=&lt;/span&gt;&lt;span class="s"&gt;"24dp"&lt;/span&gt;
    &lt;span class="na"&gt;android:height=&lt;/span&gt;&lt;span class="s"&gt;"24dp"&lt;/span&gt;
    &lt;span class="na"&gt;android:viewportWidth=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt;
    &lt;span class="na"&gt;android:viewportHeight=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt;
      &lt;span class="na"&gt;android:fillColor=&lt;/span&gt;&lt;span class="s"&gt;"#1D9B5F"&lt;/span&gt;
      &lt;span class="na"&gt;android:fillType=&lt;/span&gt;&lt;span class="s"&gt;"evenOdd"&lt;/span&gt;
      &lt;span class="na"&gt;android:pathData=&lt;/span&gt;&lt;span class="s"&gt;"M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20zM12 7a5 5 0 1 0 0 10a5 5 0 1 0 0-10z"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/vector&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;viewBox&lt;/code&gt; becomes &lt;code&gt;viewportWidth&lt;/code&gt;/&lt;code&gt;viewportHeight&lt;/code&gt; (the coordinate space the paths live in), while &lt;code&gt;width&lt;/code&gt;/&lt;code&gt;height&lt;/code&gt; in &lt;code&gt;dp&lt;/code&gt; is only the default display size. Change the viewport and you re-map the geometry; change the size and you just scale it. &lt;code&gt;d&lt;/code&gt; becomes &lt;code&gt;pathData&lt;/code&gt; with the same command syntax. The trap is the hole. Both circles in that path run in the same direction, so the hole only exists because of the even-odd fill rule. Render it with the default &lt;code&gt;nonZero&lt;/code&gt; rule and you get a solid green disc. The &lt;a href="https://developer.android.com/reference/android/graphics/drawable/VectorDrawable?hl=en" rel="noopener noreferrer"&gt;VectorDrawable reference&lt;/a&gt; lists &lt;code&gt;android:fillType&lt;/code&gt; as SDK 24+ with &lt;code&gt;nonZero&lt;/code&gt; as the default, and the same API level for gradient fills. Tracers love even-odd holes, so test icons with counters on your minimum API level, not only in the Studio preview.&lt;/p&gt;

&lt;p&gt;The importer also supports only a subset of SVG. Per the same Android page: one clipping mask per group, only centered strokes, no blend modes, no dashed paths, no filter effects (drop shadows, blurs), no text (convert it to shapes) and no pattern fills. An icon can look perfect in a browser and still lose a shadow, a mask or a label on import. Flatten those in the SVG master, keep that master, and regenerate the drawable from it rather than hand-editing two versions.&lt;/p&gt;

&lt;p&gt;Finally, know when to stop. Android recommends limiting a vector image to 200 x 200 dp, notes that the first load of a vector drawable can cost more CPU than the equivalent raster, and says detailed art such as many launch icons works better as raster. Simple icons are the sweet spot. Photos, texture and soft shadows should stay PNG.&lt;/p&gt;

&lt;p&gt;The full guide covers choosing between a direct converter and the SVG route, an XML review checklist for groups and clipping, and on-device acceptance tests: &lt;strong&gt;&lt;a href="https://perfectvector.com/blog/convert-png-to-android-vector-drawable?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=convert-png-to-android-vector-drawable&amp;amp;utm_content=dev-20261104-png-android-vector" rel="noopener noreferrer"&gt;PNG to Android Vector Drawable: An Import Checklist&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>svg</category>
      <category>mobile</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Why Auto-Traced SVGs Have Too Many Nodes: The Source Image Decides</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Mon, 09 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/why-auto-traced-svgs-have-too-many-nodes-the-source-image-decides-40kg</link>
      <guid>https://dev.to/perfectvector/why-auto-traced-svgs-have-too-many-nodes-the-source-image-decides-40kg</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You traced a PNG, opened the SVG to edit it, and the path is buried under anchor points. A curve that should take five or six points has dozens. The vectorizer isn't broken: most auto-tracers transcribe the pixel contour, and a PNG edge isn't a clean line. Anti-aliasing, compression artifacts and upscaling blur turn every edge into a slightly wobbly boundary, and the tracer adds points to follow each wobble.&lt;/p&gt;

&lt;p&gt;You can measure how much the source matters. We drew a test mark as one path with 8 segments, rendered it to a 512 px PNG in headless Chrome, made two worse copies (a JPEG at ffmpeg's lowest quality, and a 96 px version scaled back up), and traced all three with &lt;a href="https://potrace.sourceforge.net/" rel="noopener noreferrer"&gt;Potrace&lt;/a&gt; 1.16. Segments were counted with the small script from &lt;a href="https://dev.to/perfectvector/image-trace-vs-an-ai-vectorizer-count-the-paths-not-the-label-11ba"&gt;our previous post&lt;/a&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input (source mark: 8 segments)&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;-O 0.2&lt;/code&gt; (default)&lt;/th&gt;
&lt;th&gt;&lt;code&gt;-O 1&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;-O 2&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Clean 512 px render&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same image as a heavy JPEG&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;96 px, upscaled to 512&lt;/td&gt;
&lt;td&gt;87&lt;/td&gt;
&lt;td&gt;74&lt;/td&gt;
&lt;td&gt;74&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# potrace reads PBM/PGM/PPM or BMP, not PNG&lt;/span&gt;
ffmpeg &lt;span class="nt"&gt;-i&lt;/span&gt; logo.png &lt;span class="nt"&gt;-pix_fmt&lt;/span&gt; gray logo.pgm
potrace &lt;span class="nt"&gt;-s&lt;/span&gt; logo.pgm &lt;span class="nt"&gt;-o&lt;/span&gt; trace.svg          &lt;span class="c"&gt;# default curve optimization&lt;/span&gt;
potrace &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-O&lt;/span&gt; 1 logo.pgm &lt;span class="nt"&gt;-o&lt;/span&gt; trace-o1.svg  &lt;span class="c"&gt;# merge more curve segments&lt;/span&gt;
python count_nodes.py trace.svg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things stand out. First, the input decides most of the count: the same shape went from 25 segments to 87 just by starting from a blurry low-res copy, and the low-res trace also picked up a wobbly inner corner. Second, the optimization knob helps most when the source is already clean. Potrace's &lt;code&gt;-O&lt;/code&gt; (opttolerance) lets more consecutive Bézier segments merge into one "at the expense of accuracy", per its manual; on the clean render it halved the count, on the low-res one it barely moved. This is one shape and one tracer, so treat the numbers as an illustration, not a benchmark.&lt;/p&gt;

&lt;p&gt;In practice, that gives three fixes, in order of how much cleanup they save. Start from the best source you have (the original export, not a screenshot or a re-saved JPEG). Use your tracer's simplification settings and compare the silhouette before you accept them, because every simplification is lossy. Simplify afterwards in the editor (Illustrator's Object → Path → Simplify has a preview) when you only need to fix a few areas. Then count again: fewer segments for the same silhouette means easier edits, smaller path data and fewer micro-segments for a cutter or plotter to process.&lt;/p&gt;

&lt;p&gt;The full guide covers how to spot node bloat in an editor, what it does to cutting workflows, worked before/after examples and an FAQ: &lt;strong&gt;&lt;a href="https://perfectvector.com/blog/svg-too-many-nodes?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=svg-too-many-nodes&amp;amp;utm_content=dev-20261104-svg-too-many-nodes" rel="noopener noreferrer"&gt;Too Many SVG Nodes? Clean Up Your Auto-Trace Result&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>svg</category>
      <category>opensource</category>
      <category>design</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Image Trace vs an AI Vectorizer: Count the Paths, Not the Label</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Fri, 06 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/image-trace-vs-an-ai-vectorizer-count-the-paths-not-the-label-11ba</link>
      <guid>https://dev.to/perfectvector/image-trace-vs-an-ai-vectorizer-count-the-paths-not-the-label-11ba</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;"Image Trace or an AI vectorizer?" usually gets answered with labels: one is built into Illustrator, the other says AI on the box. Both do the same job, rebuilding a raster image as vector paths. Adobe documents Image Trace's presets and its controls for paths, corners, noise and colors in the &lt;a href="https://helpx.adobe.com/illustrator/desktop/manage-objects/traces-mockups-symbols/image-trace-panel-options.html" rel="noopener noreferrer"&gt;Image Trace panel guide&lt;/a&gt;, but not enough of the implementation to say which approach is "more AI". The label tells you little. The expanded output tells you a lot.&lt;/p&gt;

&lt;p&gt;Workflow is the honest split. If you already edit in Illustrator and like hand-tuning a trace before you expand it, Image Trace is right there. If you want an automated result without opening a design app, or you need an API or batch surface (some dedicated tools have one, so check the docs), test a dedicated vectorizer. Neither turns a photo into a clean SVG: continuous tone comes back as posterized art or thousands of shapes, and no tracer invents detail a low-res source never captured.&lt;/p&gt;

&lt;p&gt;What decides your cleanup time is the paths: how many segments the same shape needs, whether you can select and recolor one region instead of a welded tangle, and whether the silhouette still matches the source. So trace the same image in both, at the same intended fidelity, and put a number on it. This dependency-free script counts the drawing segments in a plain SVG:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="n"&gt;ARGS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;TOKEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;segments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Count drawing segments in one path&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s d attribute, implicit repeats included.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;TOKEN&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Z&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isalpha&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ARGS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;ARGS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;m&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# extra M pairs are lines
&lt;/span&gt;            &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tok&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;nums&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;

&lt;span class="n"&gt;svg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;path\b[^&amp;gt;]*?\sd=[\"&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]([^\"&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]*)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;images&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;image\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; paths, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;segments&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; segments, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;images&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; embedded images&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;python count_nodes.py trace-a.svg&lt;/code&gt; and &lt;code&gt;python count_nodes.py trace-b.svg&lt;/code&gt;, then put both files side by side at the same zoom. Fewer segments for the same silhouette means easier edits and lighter files downstream; a non-zero "embedded images" count means part of the file is still a bitmap. The script reads &lt;code&gt;&amp;lt;path&amp;gt;&lt;/code&gt; elements only (shapes like &lt;code&gt;&amp;lt;circle&amp;gt;&lt;/code&gt; are skipped), doesn't count the implicit closing line of &lt;code&gt;z&lt;/code&gt;, and expects arc flags separated by spaces or commas. On a 60-path test file it matched svgpathtools' segment count exactly.&lt;/p&gt;

&lt;p&gt;The full guide has the side-by-side comparison table, when each tool is the right call, where both approaches struggle, and an FAQ: &lt;strong&gt;&lt;a href="https://perfectvector.com/blog/image-trace-vs-ai-vectorizer?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image-trace-vs-ai-vectorizer&amp;amp;utm_content=dev-20261104-image-trace-vs-ai" rel="noopener noreferrer"&gt;Image Trace vs AI Vectorizer: Choose the Right Tool&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>svg</category>
      <category>python</category>
      <category>ai</category>
      <category>design</category>
    </item>
    <item>
      <title>Claude Can Write SVG. That Doesn't Mean It Vectorized Your PNG</title>
      <dc:creator>PerfectVector</dc:creator>
      <pubDate>Thu, 05 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/perfectvector/claude-can-write-svg-that-doesnt-mean-it-vectorized-your-png-2ib5</link>
      <guid>https://dev.to/perfectvector/claude-can-write-svg-that-doesnt-mean-it-vectorized-your-png-2ib5</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was drafted with AI assistance and reviewed by the PerfectVector team.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ask Claude to turn your PNG logo into an SVG and you'll get a file that opens, scales and validates. That isn't the same as vectorizing it. Writing SVG is text generation: the model emits &lt;code&gt;&amp;lt;path&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;circle&amp;gt;&lt;/code&gt; elements that describe a picture. Tracing is measurement: a system reads the pixels of one specific image and rebuilds its boundaries as geometry. Both end in &lt;code&gt;.svg&lt;/code&gt;. Only one starts from a source it has to match.&lt;/p&gt;

&lt;p&gt;Anthropic's own docs draw the same line. Claude's &lt;a href="https://support.claude.com/en/articles/8241126-upload-files-to-claude" rel="noopener noreferrer"&gt;upload guide&lt;/a&gt; says it can analyze JPEG, PNG, GIF and WebP images, and artifacts cover things like images and diagrams. Neither describes a raster-to-vector tracing feature. So "look at this logo and write SVG like it" is reconstruction by interpretation: it can work for a simple mark, but curves, proportions and small details drift.&lt;/p&gt;

&lt;p&gt;Where Claude-written SVG shines is new graphics you can describe: an icon built from a few shapes, a flowchart, a badge, a pattern. Ask for a defined &lt;code&gt;viewBox&lt;/code&gt;, no external images, and no scripts or remote resources. Then open the file in a browser (does it render?) and in a vector editor (can you select and recolor the parts?).&lt;/p&gt;

&lt;p&gt;Whatever made the file, read the markup before you ship it. A valid SVG can still be a bitmap in a wrapper, because SVG allows embedded raster content (&lt;a href="https://www.w3.org/TR/SVG2/embedded.html" rel="noopener noreferrer"&gt;W3C SVG 2, Embedded Content&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Looks like a vector, isn't one: a PNG inside an SVG wrapper --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 512 512"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;image&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"data:image/png;base64,iVBORw0KGgo..."&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"512"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"512"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Real geometry: the outline is path data you can edit --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 512 512"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt; &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"M96 256C96 168 168 96 256 96s160 72 160 160-72 160-160 160S96 344 96 256z"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#1d9b5f"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for &lt;code&gt;&amp;lt;image&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and remote &lt;code&gt;href&lt;/code&gt;s, then zoom in and see how much cleanup one simple edit takes. The rule of thumb: if you need a new graphic, let Claude write it. If you already have an image that has to stay itself (a logo, a line drawing, flat artwork), use a tracing tool and compare its paths with the source side by side.&lt;/p&gt;

&lt;p&gt;The full guide covers the three kinds of "vectorize" requests, a five-step workflow for Claude-authored SVGs, a pre-ship audit and an FAQ: &lt;strong&gt;&lt;a href="https://perfectvector.com/blog/can-claude-vectorize-an-image?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=can-claude-vectorize-an-image&amp;amp;utm_content=dev-20261104-can-claude-vectorize" rel="noopener noreferrer"&gt;Can Claude Vectorize an Image? SVG Code vs Tracing&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We build PerfectVector, an image-to-vector tool.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>svg</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
