Holiday Sale! Get over 30% off when you subscribe to an annual plan!

Sudoku API

The Sudoku API allows you to generate and solve Sudoku puzzles of various sizes and difficulty levels.

Available endpoints:

(4.6)

From 9,384 users

900+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
280ms302ms321ms664ms1068ms

Similar APIs

Didn't find what you were looking for? Suggest an improvement


/v1/sudokugenerate GET

https://api.api-ninjas.com/v1/sudokugenerate

Generate a new Sudoku puzzle with specified parameters.

Parameters

  • width  optional

    Width of each box in the Sudoku grid. Default is 3. Must be between 2 and 4.

  • height  optional

    Height of each box in the Sudoku grid. Default is 3. Must be between 2 and 4.

  • difficulty  optional

    Difficulty level of the puzzle. Possible values: easy, medium, hard. Default is medium.

  • seed  optional

    Seed value for reproducible puzzle generation.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

  • puzzle

    A 2D array representing the Sudoku puzzle grid. Empty cells are represented as null.

  • solution

    A 2D array representing the complete solution to the Sudoku puzzle.

Sample Request Live Demo!

difficulty
width
height
seed

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v1/sudokugenerate?difficulty=medium&width=3&height=3

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 { "puzzle": [ [ 4, null, 8, null, 7, 3, null, null, 9 ], [ null, 6, 9, null, 4, 2, null, 8, 7 ], [ 2, null, null, null, 5, null, null, 4, 6 ], [ 6, 7, 3, null, 1, null, null, 9, null ], [ 9, 2, 4, null, 6, null, null, null, 8 ], [ null, null, 5, 2, 9, null, 6, 7, 3 ], [ 3, null, 2, 9, null, 1, null, null, 5 ], [ null, null, null, null, null, null, null, null, null ], [ null, 5, null, null, 3, 6, 9, 2, null ] ], "solution": [ [ 4, 1, 8, 6, 7, 3, 2, 5, 9 ], [ 5, 6, 9, 1, 4, 2, 3, 8, 7 ], [ 2, 3, 7, 8, 5, 9, 1, 4, 6 ], [ 6, 7, 3, 5, 1, 8, 4, 9, 2 ], [ 9, 2, 4, 3, 6, 7, 5, 1, 8 ], [ 1, 8, 5, 2, 9, 4, 6, 7, 3 ], [ 3, 4, 2, 9, 8, 1, 7, 6, 5 ], [ 7, 9, 6, 4, 2, 5, 8, 3, 1 ], [ 8, 5, 1, 7, 3, 6, 9, 2, 4 ] ] }

Code Examples

1 2 curl -X GET "https://api.api-ninjas.com/v1/sudoku?difficulty=easy" \ -H "X-Api-Key: YOUR_API_KEY"

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.


/v1/sudokusolve GET

https://api.api-ninjas.com/v1/sudokusolve

Solve an existing Sudoku puzzle.

Parameters

  • puzzle  required

    2D JSON array representing the Sudoku puzzle. Use 0 for empty cells.

  • width  required

    Width of each box in the Sudoku grid. Must be between 2 and 4.

  • height  required

    Height of each box in the Sudoku grid. Must be between 2 and 4.

Headers

  • X-Api-Key  required

    API Key associated with your account.

  • Content-Type  required

    Must be set to application/json.

Response

  • status

    The status of the solution attempt. Possible values: solved or unsolvable.

  • solution

    A 2D array representing the solved Sudoku puzzle. Only present if status is solved.

Sample Request

puzzle
width
height

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v1/sudokusolve

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 { "status": "solved", "solution": [ [ 4, 3, 5, 2, 6, 9, 7, 8, 1 ], [ 6, 8, 2, 5, 7, 1, 4, 9, 3 ], [ 1, 9, 7, 8, 3, 4, 5, 6, 2 ], [ 8, 2, 6, 1, 9, 5, 3, 4, 7 ], [ 3, 7, 4, 6, 8, 2, 9, 1, 5 ], [ 9, 5, 1, 7, 4, 3, 6, 2, 8 ], [ 5, 1, 9, 3, 2, 6, 8, 7, 4 ], [ 2, 4, 8, 9, 5, 7, 1, 3, 6 ], [ 7, 6, 3, 4, 1, 8, 2, 5, 9 ] ] }