# Quickstart

> Three ways to get your first answer from Pie in five minutes.

Source: https://pie-project.org/docs/quickstart  

You can start with Pie in three ways depending on what you want to build.

- [Call it like OpenAI](#call-it-like-openai): Start pie serve and use your existing OpenAI, Anthropic, or Gemini client.

- [Run an inferlet](#run-an-inferlet): Write a 20-line Python program that drives the generation loop.

- [Try it in your browser](#try-it-in-your-browser): Run Pie in a browser tab over WebGPU with nothing to install.

The first two paths require Pie [installed](https://pie-project.org/docs/install) and one model imported:

```bash
pie config init
pie model import Qwen/Qwen3.5-0.8B
```

## Call it like OpenAI

Start the server. It listens on `127.0.0.1:8080` by default.

```bash
pie serve
```

Call it with any OpenAI client. Use `"default"` as the model name, which matches the `[model]` section created by `pie config init`:

Python:

```python
from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="unused")
reply = client.chat.completions.create(
    model="default",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(reply.choices[0].message.content)
```

curl:

```bash
curl http://127.0.0.1:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "default", "messages": [{"role": "user", "content": "What is the capital of France?"}]}'
```

The same port also serves the Anthropic and Gemini APIs. See [Serve an API](https://pie-project.org/docs/serve/api).

## Run an inferlet

An inferlet is a program that runs inside the engine and drives the model one forward pass at a time. Save this script as `main.py`:

```python title="main.py"
from inferlet import chat, model
from inferlet.eta import ForwardPass, Pipeline, StateGeometry, WorkingSet, intrinsics, reduce_argmax

async def main(input: dict) -> dict:
    tokens = chat.prefix() + model.encode(input.get("prompt", "The capital of France is"))
    max_tokens = int(input.get("max_tokens", 8))
    ws = WorkingSet()
    pipe = Pipeline()

    done = 0
    for _ in range(max_tokens):
        fwd = ForwardPass()
        fwd.embed(tokens[done:])
        fwd.state([ws], StateGeometry.folding())
        out = fwd.epilogue(lambda: reduce_argmax(intrinsics.output(0, "logits")))
        pipe.submit(fwd)
        done = len(tokens)
        tokens.append(await out)
    pipe.close()

    return {"text": model.decode(tokens[-max_tokens:])}
```

Run it with `pie run`. Flags after `--` become keys in the `input` dictionary, so `--max-tokens 16` arrives as `{"max_tokens": 16}`:

```bash
pie run main.py -- --prompt "The capital of France is" --max-tokens 16
```

You control every step of that loop: what tokens go in, how the next token is chosen, and when to stop. [How Pie thinks](https://pie-project.org/docs/how-pie-thinks) explains each primitive, and [Your first inferlet](https://pie-project.org/docs/program/first-inferlet) extends this example with chat templates and streaming.

## Try it in your browser

Open the [Playground](https://pie-project.org/playground). It downloads a small model once and runs Pie in your browser on WebGPU. Each example is an interactive inferlet with its Python source alongside the chat: multi-turn sessions, custom samplers, grammar constraints, prefix forking, speculative lookup, token-level introspection, vision, image generation, and speech.

## Where next

- [Serve](https://pie-project.org/docs/serve): Choose models and devices, tune kernels, embed Pie, or scale across a cluster.

- [Program](https://pie-project.org/docs/program): Build tool calls, structured output, multi-turn sessions, branching, and agents.

- [Invent](https://pie-project.org/docs/invent): Write device samplers, speculative decoders, KV cache policies, and Poem models.
