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
From 9,384 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 280ms | 302ms | 321ms | 664ms | 1068ms |
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
widthoptionalWidth of each box in the Sudoku grid. Default is
3. Must be between2and4.heightoptionalHeight of each box in the Sudoku grid. Default is
3. Must be between2and4.difficultyoptionalDifficulty level of the puzzle. Possible values:
easy,medium,hard. Default ismedium.seedoptionalSeed value for reproducible puzzle generation.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON object with the following fields or an error if the request is unsuccessful.
puzzleA 2D array representing the Sudoku puzzle grid. Empty cells are represented as
null.solutionA 2D array representing the complete solution to the Sudoku puzzle.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/sudokugenerate?difficulty=medium&width=3&height=3Headers
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/sudokugenerate?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
puzzlerequired2D JSON array representing the Sudoku puzzle. Use
0for empty cells.widthrequiredWidth of each box in the Sudoku grid. Must be between
2and4.heightrequiredHeight of each box in the Sudoku grid. Must be between
2and4.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Content-TyperequiredMust be set to
application/json.
Response
A JSON object with the following fields or an error if the request is unsuccessful.
statusThe status of the solution attempt. Possible values:
solvedorunsolvable.solutionA 2D array representing the solved Sudoku puzzle. Only present if
statusissolved.
Sample Request
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/sudokusolveHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Frequently Asked Questions
Can I use the Sudoku API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Sudoku API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Sudoku API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Sudoku API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What is the difference between the two Sudoku API endpoints?
The Sudoku API has two endpoints:/v1/sudokugeneratecreates a brand-new puzzle with both apuzzlegrid and itssolution, while/v1/sudokusolvetakes an existingpuzzleyou supply and returns itssolution. Both are GET requests authenticated with your API key from your account.How do I generate a puzzle of a specific difficulty or size?
On/v1/sudokugenerate, use thedifficultyparameter (easy,medium, orhard, defaulting tomedium) and thewidthandheightparameters to set each box's dimensions, both defaulting to3and accepting values between2and4. You can also pass aseedvalue for reproducible puzzle generation. See pricing for request volume options.How do I solve my own Sudoku puzzle and what does the response look like?
Call/v1/sudokusolvewith a requiredpuzzleparameter (a 2D JSON array using0for empty cells) plus the matchingwidthandheightof each box; the response returns astatusofsolvedorunsolvable, and asolution2D array when solved. If something goes wrong, consult the error codes.What are some use cases for the Sudoku API?
You can use it to power puzzle apps, daily challenge games, or printable worksheets by generating puzzles via/v1/sudokugenerate, and to validate or auto-complete user-entered grids via/v1/sudokusolve. For more puzzle and quiz content, pair it with the Riddles API, Trivia API, or Facts API.