NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

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

A JSON object with the following fields or an error if the request is unsuccessful.

  • 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 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=3

Headers

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

Sample Response

JSON
{
    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/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

  • 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

A JSON object with the following fields or an error if the request is unsuccessful.

  • 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 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/sudokusolve

Headers

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

Sample Response

JSON
{
    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
      ]
    ]
}

Frequently Asked Questions

  • 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.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • The Sudoku API has two endpoints: /v1/sudokugenerate creates a brand-new puzzle with both a puzzle grid and its solution, while /v1/sudokusolve takes an existing puzzle you supply and returns its solution. Both are GET requests authenticated with your API key from your account.
  • On /v1/sudokugenerate, use the difficulty parameter (easy, medium, or hard, defaulting to medium) and the width and height parameters to set each box's dimensions, both defaulting to 3 and accepting values between 2 and 4. You can also pass a seed value for reproducible puzzle generation. See pricing for request volume options.
  • Call /v1/sudokusolve with a required puzzle parameter (a 2D JSON array using 0 for empty cells) plus the matching width and height of each box; the response returns a status of solved or unsolvable, and a solution 2D array when solved. If something goes wrong, consult the error codes.
  • 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.