API Directory › 🎮 Games › Deck of Cards
No authHTTPSCORS

Deck of Cards API

Simulate shuffling and drawing from decks of playing cards via a simple API.

Category
Auth
No auth needed
HTTPS
Yes
CORS
Yes
Open Deck of Cards docs ↗

What it does

Deck of Cards API is a stateful playing-card service: create and shuffle a deck (or several), draw cards, and move cards between named piles. Each card comes with an image URL. The deck’s state is held server-side and referenced by a deck_id.

Base URL

https://deckofcardsapi.com/api/deck

Authentication

None. /new/shuffle/?deck_count=1 to start, then /{deck_id}/draw/?count=2, /{deck_id}/shuffle/, /{deck_id}/pile/{name}/add/?cards=AS,KH and /{deck_id}/pile/{name}/list/.

Code examples

curl
DECK=$(curl -s "https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1" | jq -r .deck_id)
curl -s "https://deckofcardsapi.com/api/deck/$DECK/draw/?count=5"
Python
import requests

d = requests.get("https://deckofcardsapi.com/api/deck/new/shuffle/", timeout=10).json()
hand = requests.get(f"https://deckofcardsapi.com/api/deck/{d['deck_id']}/draw/",
                    params={"count": 5}, timeout=10).json()
for c in hand["cards"]:
    print(c["value"], "of", c["suit"], "-", c["image"])
print("remaining:", hand["remaining"])

Rate limits & quotas

No documented rate limit. Decks are kept for a period of inactivity then expire — persist the deck_id if a game needs to resume later, and be ready to create a new deck if an old id returns an error. Use ?deck_count= for multi-deck games and a brand-new deck for the ‘jokers_enabled’ option.

Key response fields

deck_idHandle for all subsequent calls
shuffled / remainingDeck state
cards[].codeTwo-char code, e.g. AS, 0H (ten of hearts), KD
cards[].value / suite.g. ACE / SPADES
cards[].image / images.svg / images.pngCard face images
piles.{name}.remainingCount in each named pile

Common errors

success: false, errorUsually an expired/unknown deck_id or drawing more cards than remain.
(ten is '0')The ten card’s code is 0 + suit (0S), not 10S.
404Malformed path (missing trailing slash on some endpoints).

When to use it (and alternatives)

Ideal for card games (blackjack, poker, solitaire, war), card-draw mechanics, and teaching state management with a friendly API. For collectible card game data see Scryfall.

FAQ

How do I deal hands to players?

Draw the cards, then add each player’s cards to a named pile: /{deck_id}/pile/player1/add/?cards=AS,KH. /pile/player1/list/ shows that hand; you can draw from a pile too.

Do decks last forever?

No — an idle deck eventually expires. For a persistent game, store the deck_id and handle the case where a call fails by creating a fresh deck.

Why is the ten card code weird?

Card codes are two characters. The ten uses 0 so every code is exactly two chars: 0H is the ten of hearts.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

JSON Formatter

Related Games APIs

← Back

More Games APIs · All 196 APIs