Sudoku API
The Sudoku API allows you to generate and solve Sudoku puzzles of various sizes and difficulty levels.
Available endpoints:
- /v1/sudokugenerate - Generate a new Sudoku puzzle
- /v1/sudokusolve - Solve an existing Sudoku puzzle
Checking API status...
/v1/sudokugenerate GET
https://api.api-ninjas.com/v1/sudokugenerate
Generate a new Sudoku puzzle with specified parameters.
Parameters
- widthoptional- Width of each box in the Sudoku grid. Default is - 3. Must be between- 2and- 4.
- heightoptional- Height of each box in the Sudoku grid. Default is - 3. Must be between- 2and- 4.
- difficultyoptional- Difficulty level of the puzzle. Possible values: - easy,- medium,- hard. Default is- medium.
- seedoptional- Seed value for reproducible puzzle generation. 
Headers
- X-Api-Keyrequired- API Key associated with your account. 
Sample Request Live Demo!
https://api.api-ninjas.com/v1/sudokugenerateHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
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]
  ]
}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
- puzzlerequired- 2D JSON array representing the Sudoku puzzle. Use - 0for empty cells.
- widthrequired- Width of each box in the Sudoku grid. Must be between - 2and- 4.
- heightrequired- Height of each box in the Sudoku grid. Must be between - 2and- 4.
Headers
- X-Api-Keyrequired- API Key associated with your account. 
- Content-Typerequired- Must be set to - application/json.
Sample Request
https://api.api-ninjas.com/v1/sudokusolveHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
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]
  ]
}