Skip to content

Quickstart: self-host

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

Applies to Engine
View as Markdown
On this page
  1. Start the gateway
  2. Give a task its route
  3. Call it

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
    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 }
    Terminal
    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.

    Terminal
    export SYPNIA_AI_URL=http://localhost:8095 SYPNIA_AI_TOKEN=$SYPNIA_GATEWAY_ROOT_TOKEN
    npx @sypnia/ai models --task write
    sypnia.toml
    [ai.tasks.write]
    model = "openrouter/<model id from the list>"
    instructions = "You write for La Espiga, a neighbourhood bakery. Warm, short, in Spanish."
    Terminal
    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:

    Terminal
    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), and add Amazon Bedrock or a local model (Providers).

  1. Start the gateway
  2. Give a task its route
  3. Call it

    Search pages, sections and terms