# Build a game

URL: https://docs.hanzo.ai/docs/games

> The shortest path from nothing to something you can play — in the browser, from your terminal, or against the raw API.

A game is the fastest honest test of a platform. It has to render, it has to keep
state, it has to respond in a loop, and you know within a second whether it works —
no staging environment, no "looks right to me". So we use one to introduce the three
ways to build on Hanzo.

Same game, three paths. Pick by how much you want to type.

**In the browser**

No install, no key, nothing to configure. Open [hanzo.app](https://hanzo.app), sign
in, and describe the game:

```text
Build a single-page snake game. Arrow keys to move, the snake grows when it
eats, and the score is kept in the corner. Game over on hitting a wall or
yourself, with a restart button. Use a canvas, no dependencies.
```

You get a running preview beside the chat. Keep going in plain English — _make the
snake faster as the score climbs_, _add a high score that survives a refresh_,
_make it playable on a phone_ — and the preview updates as it goes.

When it plays the way you want, publish it. It gets a URL on `hanzo.app` you can
send to someone.

> This is the same model and the same tools as the other two paths. The only
> difference is that the app writes the code and hosts the result for you.

**From your terminal**

Install the CLI and sign in — two commands, and you have a credential every later
command and SDK on the machine will use:

```bash
curl -fsSL https://hanzo.sh | sh
hanzo auth login
```

Then hand the job to [Dev](https://docs.hanzo.ai/docs/cli), our coding agent. It works in a real
directory, so it can read what is already there, write files and run things:

```bash
mkdir snake && cd snake
hanzo dev "Build a single-page snake game with a canvas and no dependencies.
Arrow keys to move, the snake grows when it eats, score in the corner, game
over on hitting a wall or yourself, restart button."
```

Open the file it wrote and play it. Then keep iterating in the same directory —
Dev has the codebase in front of it, so later instructions are about _this_ game,
not a fresh one:

```bash
hanzo dev "make it speed up as the score climbs, and persist a high score"
hanzo dev "write tests for the collision logic and run them"
```

**Against the API**

If you want the model directly, it is one POST. Any language, any framework —
the [request shape](https://docs.hanzo.ai/docs/openapi) is the widely-implemented chat-completions
format, so a client you already have works by changing the base URL and the key.

Mint a key at [platform.hanzo.ai](https://platform.hanzo.ai) (see
[API Keys](https://docs.hanzo.ai/docs/api-keys)), then:

```bash
curl https://api.hanzo.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "enso",
    "messages": [{
      "role": "user",
      "content": "Write a complete single-file HTML snake game. Canvas, no dependencies. Arrow keys, growth on eating, score in the corner, game over on wall or self collision, restart button. Reply with only the HTML."
    }]
  }'
```

Write the response to `snake.html` and open it. The same thing in Python:

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["HANZO_API_KEY"],
    base_url="https://api.hanzo.ai/v1",
)

game = client.chat.completions.create(
    model="enso",
    messages=[{"role": "user", "content": "Write a complete single-file HTML snake game..."}],
)

open("snake.html", "w").write(game.choices[0].message.content)
```

`model` is the only thing to change to try [another model](https://docs.hanzo.ai/docs/openapi/ai) — the
request shape does not move.

## Make it multiplayer

The single-player version is local state in one browser tab. Two players need
somewhere shared to put the state, and something to tell each tab when it changed —
which is the point at which a toy starts using the platform properly:

- [Keep the scores](https://docs.hanzo.ai/docs/openapi/kv): A key/value store for the leaderboard — read and written from the browser.
- [Push the moves](https://docs.hanzo.ai/docs/openapi/pubsub): Publish each move, subscribe in the other tab. No polling loop to write.
- [Know who is playing](https://docs.hanzo.ai/docs/openapi/iam): Sign-in, so a high score belongs to a person instead of a browser.
- [Put it somewhere](https://docs.hanzo.ai/docs/openapi/deploy): Ship the finished thing to a URL you can send to someone.

## Then take it further

- [Get Started](https://docs.hanzo.ai/docs/quickstart): Account, API key, first call — the five-minute version.
- [API Reference](https://docs.hanzo.ai/docs/openapi): Every endpoint, generated from OpenAPI.
- [SDKs](https://docs.hanzo.ai/docs/sdks): Python, TypeScript, Go, Rust — one contract, many bindings.
- [MCP](https://docs.hanzo.ai/docs/mcp): Give the model real tools — files, HTTP, your own functions.
