Random Color Generator API: Generate Random Colors

Need random colors for testing, placeholder content, or creative applications? This guide covers the Random Color Generator API, which produces random colors with optional constraints to ensure usable, aesthetically pleasing results.

Types of Random Colors

Not all random colors are equally useful. True random RGB can produce muddy, unpleasant colors. The API offers several modes:

  • Pure random: Any possible color (may be ugly)
  • Bright: High saturation, medium lightness (vibrant)
  • Pastel: High lightness, medium saturation (soft)
  • Dark: Low lightness (rich, deep colors)
  • Light: High lightness (soft, airy colors)

Constraining Randomness

The API allows you to constrain the randomness to get more usable results:

  • Hue range: Limit to specific color families (e.g., blues only)
  • Saturation range: Control color intensity
  • Lightness range: Control brightness level
  • Presets: Use built-in presets for common needs
Tip: For user-distinguishable colors, use the "distinct" mode which ensures generated colors are visually different from each other.

Using the Random Color API

TinyFn provides a flexible random color endpoint:

API Request
GET https://api.tinyfn.io/v1/color/random
Headers: X-API-Key: your-api-key
Response
{
  "colors": [
    {
      "hex": "#3498db",
      "rgb": { "r": 52, "g": 152, "b": 219 },
      "hsl": { "h": 204, "s": 70, "l": 53 },
      "name": "Curious Blue"
    }
  ],
  "mode": "bright",
  "count": 1
}

Parameters

Parameter Type Description
count integer Number of colors to generate (1-20). Default: 1
mode string Preset mode: random, bright, pastel, dark, light, distinct. Default: bright
hue_min integer Minimum hue (0-360)
hue_max integer Maximum hue (0-360)
saturation_min integer Minimum saturation (0-100)
saturation_max integer Maximum saturation (0-100)
lightness_min integer Minimum lightness (0-100)
lightness_max integer Maximum lightness (0-100)

Code Examples

JavaScript / Node.js

// Generate 5 bright random colors
const response = await fetch(
  'https://api.tinyfn.io/v1/color/random?' + new URLSearchParams({
    count: 5,
    mode: 'bright'
  }),
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();

result.colors.forEach((color, i) => {
  console.log(`Color ${i + 1}: ${color.hex} (${color.name})`);
});

// Generate random blues only
const blues = await fetch(
  'https://api.tinyfn.io/v1/color/random?' + new URLSearchParams({
    count: 3,
    hue_min: 180,
    hue_max: 240
  }),
  { headers: { 'X-API-Key': 'your-api-key' } }
).then(r => r.json());

Python

import requests

# Generate pastel colors
response = requests.get(
    'https://api.tinyfn.io/v1/color/random',
    params={'count': 5, 'mode': 'pastel'},
    headers={'X-API-Key': 'your-api-key'}
)
result = response.json()

print("Random pastel colors:")
for color in result['colors']:
    print(f"  {color['hex']} - {color['name']}")

cURL

curl "https://api.tinyfn.io/v1/color/random?count=3&mode=distinct" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Placeholder Content: Generate colors for mockups and wireframes
  • Data Visualization: Color-code data categories dynamically
  • User Avatars: Assign random colors to user profiles
  • Games: Generate random visual elements
  • Testing: Test UI with various color combinations

Best Practices

  1. Use modes: Preset modes produce better results than pure random
  2. Use distinct for sets: When generating multiple colors, use "distinct" mode
  3. Constrain for brand: Limit hue ranges to match your brand colors
  4. Consider accessibility: Random colors may not meet contrast requirements

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-color": {
      "url": "https://api.tinyfn.io/mcp/color/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all color tools available via MCP in our Color MCP Tools for AI Agents guide.

Try the Random Color Generator API

Get your free API key and start generating random colors.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key