The Sudoku API allows you to generate and solve Sudoku puzzles of various sizes and difficulty levels.
Available endpoints:
https://api.api-ninjas.com/v1/sudokugenerate
Generate a new Sudoku puzzle with specified parameters.
width
optionalWidth of each box in the Sudoku grid. Default is 3
. Must be between 2
and 4
.
height
optionalHeight of each box in the Sudoku grid. Default is 3
. Must be between 2
and 4
.
difficulty
optionalDifficulty level of the puzzle. Possible values: easy
, medium
, hard
. Default is medium
.
seed
optionalSeed value for reproducible puzzle generation.
X-Api-Key
requiredAPI Key associated with your account.
https://api.api-ninjas.com/v1/sudokugenerate
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"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]
]
}
1
2
3
4
5
6
7
8
import requests
api_url = 'https://api.api-ninjas.com/v1/sudokugenerate?difficulty=easy'
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
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.
https://api.api-ninjas.com/v1/sudokusolve
Solve an existing Sudoku puzzle.
puzzle
required2D JSON array representing the Sudoku puzzle. Use 0
for empty cells.
width
requiredWidth of each box in the Sudoku grid. Must be between 2
and 4
.
height
requiredHeight of each box in the Sudoku grid. Must be between 2
and 4
.
X-Api-Key
requiredAPI Key associated with your account.
Content-Type
requiredMust be set to application/json
.
https://api.api-ninjas.com/v1/sudokusolve
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"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]
]
}