Coin Flip

Coin Flip API

Utilities

Flip a coin online for heads or tails with a 3D animation, flip up to 20 coins at once, track the tally and streaks, or play best of 3, 5 or 7.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Flip one or more coins, or play a best-of-3, 5 or 7 match. Flips use the server's crypto-secure random generator, and each side has exactly the same chance.

Modes

  • Flips (default): send count (1 to 1000). The response lists every flip in order, with the heads and tails totals, the current streak and the longest streak of each side.
  • Match: send bestOf (3, 5 or 7). Coins are flipped one at a time until a side reaches the majority, and the response has the flips, the score and the winner. When bestOf is set, count is ignored.

Endpoints

POST
https://opentools.ca/api/v1/tools/coin-flip
Flip coins or play a best-of match

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
count
number
OptionalNumber of coins to flip, 1 to 1000. Ignored when bestOf is set.Default: 1
bestOf
number
Enum: 3, 5, 7
OptionalPlay a match instead: first side to a majority wins. Must be 3, 5 or 7.

Response Example

{
  "success": true,
  "mode": "flips",
  "count": 5,
  "flips": [
    "heads",
    "heads",
    "tails",
    "heads",
    "tails"
  ],
  "heads": 3,
  "tails": 2,
  "total": 5,
  "current": {
    "side": "tails",
    "length": 1
  },
  "longestHeads": 2,
  "longestTails": 1
}

Error Codes

400
Bad Request - count out of range or bestOf not 3, 5 or 7
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key inactive, expired, or request from a disallowed IP
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

# Flip five coins
curl -X POST https://opentools.ca/api/v1/tools/coin-flip \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"count": 5}'

# Best of 5 match
curl -X POST https://opentools.ca/api/v1/tools/coin-flip \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"bestOf": 5}'

Ready to get started?

Create an API key to start using the Coin Flip API.

Rather use it in your browser? Open the Coin Flip