# Quickstart: self-host

> Run the open-source gateway with Docker and your own OpenRouter key, and make a first call.

Applies to: the Sypnia engine (open source, self-hosted).  
Source: https://ai.docs.sypnia.com/start/quickstart-self-host/

For agents: Self-host quickstart: compose.yaml with ghcr.io/sespinosav/sypnia-ai + postgres:16; env SYPNIA_GATEWAY_DATABASE_URL, SYPNIA_GATEWAY_ROOT_TOKEN, SYPNIA_GATEWAY_OPENROUTER_KEY, SYPNIA_GATEWAY_AUTO_MIGRATE=true; port 8095; ai routes apply --url http://localhost:8095 with an explicit model id (no default model when self-hosted); keys create; OpenAI-compatible call with curl.

At the end you will have the gateway on `http://localhost:8095`, reaching models with your own OpenRouter key.

### 1. Start the gateway

`compose.yaml`

```yaml
services:
  ai:
    image: ghcr.io/sespinosav/sypnia-ai:1
    ports: ["8095:8095"]
    environment:
      SYPNIA_GATEWAY_DATABASE_URL: postgres://sypnia:sypnia@db:5432/sypnia_ai
      SYPNIA_GATEWAY_ROOT_TOKEN: ${SYPNIA_GATEWAY_ROOT_TOKEN}
      SYPNIA_GATEWAY_OPENROUTER_KEY: ${OPENROUTER_API_KEY}
      SYPNIA_GATEWAY_AUTO_MIGRATE: "true"
    depends_on: [db]
  db:
    image: postgres:16
    environment: { POSTGRES_USER: sypnia, POSTGRES_PASSWORD: sypnia, POSTGRES_DB: sypnia_ai }
```

```bash
export SYPNIA_GATEWAY_ROOT_TOKEN=$(openssl rand -hex 32)
docker compose up -d
curl -s http://localhost:8095/v1/health
```

**You should see:**`{"status":"ok","providers":{"openrouter":"ok"}}`

### 2. Give a task its route

A self-hosted gateway has no default model, on purpose: you choose it. List what your key can reach, then write the route with that id.

```bash
export SYPNIA_AI_URL=http://localhost:8095 SYPNIA_AI_TOKEN=$SYPNIA_GATEWAY_ROOT_TOKEN
npx @sypnia/ai models --task write
```

`sypnia.toml`

```toml
[ai.tasks.write]
model = "openrouter/<model id from the list>"
instructions = "You write for La Espiga, a neighbourhood bakery. Warm, short, in Spanish."
```

```bash
npx @sypnia/ai routes apply
npx @sypnia/ai keys create la-espiga-server --scope call
```

### 3. Call it

The API speaks the same language as OpenAI's, so `curl` or any OpenAI client works:

```bash
curl -s http://localhost:8095/v1/chat/completions \
  -H "Authorization: Bearer $SYPNIA_SECRET_KEY" \
  -H "Sypnia-Case: publish-bread-of-the-day" \
  -H "Content-Type: application/json" \
  -d '{"model":"task:write","messages":[{"role":"user","content":"Today: rye loaf."}]}'
```

**You should see:**A `chat.completion` object, with a `sypnia` field carrying the route, the model used and the cost in your provider's currency.

Next: send the spans to Telemetry with `SYPNIA_GATEWAY_OTLP_ENDPOINT` ([Configuration](https://ai.docs.sypnia.com/self-hosting/configuration)), and add Amazon Bedrock or a local model ([Providers](https://ai.docs.sypnia.com/models/providers)).
