Examples
Quick examples for common use cases with the Color API.
Convert a Color
Section titled “Convert a Color”const response = await fetch( "https://color.koval.dev/v1/convert?value=%23ff0000", { headers: { Authorization: "Bearer YOUR_API_KEY" } },);const data = await response.json();console.log(data.formats.rgb); // { r: 255, g: 0, b: 0 }Check Accessibility
Section titled “Check Accessibility”const response = await fetch("https://color.koval.dev/v1/analyze", { method: "POST", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ foreground: "#000000", background: "#ffffff", }),});const data = await response.json();console.log(data.accessibility.wcag.contrast_ratio); // 21Get Color Name
Section titled “Get Color Name”const response = await fetch( "https://color.koval.dev/v1/name?value=%23ff0000&limit=3", { headers: { Authorization: "Bearer YOUR_API_KEY" } },);const data = await response.json();console.log(data.matches);// [{ name: 'red', hex: '#ff0000', dataset: 'css' }, ...]Generate Palette
Section titled “Generate Palette”const response = await fetch( "https://color.koval.dev/v1/palette?value=%236366f1&type=complementary", { headers: { Authorization: "Bearer YOUR_API_KEY" } },);const data = await response.json();console.log(data.palette);// [{ hex: '#6366F1', oklch: {...} }, ...]More Examples
Section titled “More Examples”See the API Reference for all available endpoints.