Convert colors between hex, RGB, and HSL with one API call
Color conversion math is the kind of code you write once, get subtly wrong, and copy between projects forever. Hex to RGB is straightforward; RGB to HSL is where the off-by-a-degree bugs live. This endpoint takes a color in any of the three formats and returns all three at once, so you stop carrying conversion functions around.
The request
curl -X POST https://api.botoi.com/v1/color/convert \
-H "Content-Type: application/json" \
-d '{"color": "#3EC997"}'
The response gives you the hex string, an { r, g, b } object, and an
{ h, s, l } object together:
{
"data": {
"hex": "#3EC997",
"rgb": { "r": 62, "g": 201, "b": 151 },
"hsl": { "h": 158, "s": 56, "l": 52 }
}
}
Input format does not matter. Pass rgb(62, 201, 151) or an HSL string and you get the
same three representations back. Hex works with or without the #:
# RGB and HSL inputs work too; you always get all three back.
curl -X POST https://api.botoi.com/v1/color/convert \
-H "Content-Type: application/json" \
-d '{"color": "rgb(62, 201, 151)"}' Generate a design-token scale from one brand color
HSL is the format worth building on. Because it separates hue from lightness, you can produce a full tint-and-shade scale by holding hue and saturation steady and stepping the lightness value. Convert your brand hex to HSL once, then walk the lightness to generate the 50-to-900 scale a design system needs:
// Build a design-token file at build time from one brand color.
// Hold hue and saturation, step lightness to make a 50-900 scale.
async function toHsl(color) {
const res = await fetch("https://api.botoi.com/v1/color/convert", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ color }),
});
const { data } = await res.json();
return data.hsl; // { h, s, l }
}
const brand = await toHsl("#3EC997");
const steps = { 50: 95, 100: 90, 200: 80, 300: 68, 400: 60, 500: 52, 600: 44, 700: 35, 800: 26, 900: 17 };
const scale = {};
for (const [name, l] of Object.entries(steps)) {
scale[name] = `hsl(${brand.h} ${brand.s}% ${l}%)`;
}
console.log(scale["500"]); // hsl(158 56% 52%) Run that in a build step and write the output to a CSS variables file. You get a coordinated palette from a single source color, and changing the brand color regenerates the whole scale:
:root {
/* Generated from one brand hex, expressed as HSL for easy theming */
--brand-50: hsl(158 56% 95%);
--brand-500: hsl(158 56% 52%);
--brand-900: hsl(158 56% 17%);
}
Need a full palette rather than a single conversion? The /v1/color/palette
endpoint takes one base color and returns a coordinated set of shades and complementary colors,
so you can theme around a brand color without picking each swatch by hand.
Normalize colors pasted into a CMS
Content editors paste colors in whatever format their design tool exports: a hex from Figma, an
rgb() from a screenshot tool, an HSL from a CSS snippet. Run every pasted value
through the endpoint on save and store the normalized hex. Your rendering code then deals with one
format, and the editor keeps pasting whatever is convenient.
Where it fits
For interactive UI math in the browser, a local function is fine. The API earns its place in build steps, backends, and any language without a solid color package: a single HTTP call replaces a dependency. Color conversion is one of roughly 200 single-purpose endpoints on botoi, all behind one key with 5 req/min free.
Try the conversion in the interactive playground, browse the full API docs, or connect the MCP server to convert colors straight from Claude or Cursor.
Frequently asked questions
- What color formats does the API accept and return?
- Send a color as HEX, RGB, or HSL and the response returns all three representations at once. Hex strings work with or without the leading # prefix. One call gives you the hex string, an {r, g, b} object, and an {h, s, l} object, so you never write conversion math by hand.
- Why convert colors over an API instead of in the browser?
- For one-off UI math, do it in the browser. The API earns its place in build steps and backends: generating design tokens at build time, normalizing colors pasted into a CMS, or producing themed assets server-side where you do not want to ship a color library. It is a single HTTP call from any language, including ones without a good color package.
- Can I generate a full palette, not just convert one color?
- Yes. The color/palette endpoint takes a base color and returns a coordinated set of shades and complementary colors. Use color/convert when you have a known color and need its other representations, and color/palette when you have one brand color and need a scale to build a theme around it.
- How do HSL values help with theming?
- HSL separates hue from saturation and lightness, so you can build a tint and shade scale by holding hue and saturation steady and stepping lightness. That is far easier to reason about than nudging three RGB channels. Convert your brand hex to HSL once, then generate the 50-to-900 scale by walking the lightness value.
- Is the color API free to use?
- Yes. Color conversion sits behind the same free tier as the rest of botoi: 5 requests per minute with no API key required, and higher limits on paid plans. It is one of roughly 200 single-purpose endpoints under one key.
Try this API
Color Convert API — interactive playground and code examples
More tutorial posts
Start building with botoi
150+ API endpoints for lookup, text processing, image generation, and developer utilities. Free tier, no credit card.