Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ GEMINI_API_KEY=
# Optional tuning
GATEWAY_PUBLIC_MODELS=true
GATEWAY_CORS_ORIGINS=*
GATEWAY_BOOTSTRAP_DEMO_KEY=true
# No demo key and no example providers/routes on a real deployment.
GATEWAY_BOOTSTRAP_DEMO_KEY=false
GATEWAY_SEED_DEFAULTS=false
GATEWAY_DEFAULT_RPM=120
# GATEWAY_DEFAULT_CREDIT_USD=25

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
mkdir -p /tmp/opencode
python3 tools/mock-upstream.py 9099 > /tmp/opencode/mock.log 2>&1 &
GATEWAY_ADMIN_TOKEN=test-admin \
GATEWAY_SEED_DEFAULTS=true \
GATEWAY_PROMPT_LOGGING=true \
GATEWAY_GUARDRAILS_MODERATION=true \
GATEWAY_SEMANTIC_MODEL=embed-test \
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependency: the gateway translates to each provider's native protocol.

# full end-to-end suite against a mock upstream (no real keys)
python3 tools/mock-upstream.py 9099 &
GATEWAY_ADMIN_TOKEN=test-admin java -jar path-gateway/target/path-*.jar &
GATEWAY_ADMIN_TOKEN=test-admin GATEWAY_SEED_DEFAULTS=true java -jar path-gateway/target/path-*.jar &
python3 tools/smoke_test.py

# run locally
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verbatim as the body of the matching GitHub release.

| Version | Date | Notes |
|---|---|---|
| v0.2.4 | 2026-11-23 | [changelog/v0.2.4.md](changelog/v0.2.4.md) |
| v0.2.3 | 2026-11-20 | [changelog/v0.2.3.md](changelog/v0.2.3.md) |
| v0.2.2 | 2026-11-17 | [changelog/v0.2.2.md](changelog/v0.2.2.md) |
| v0.2.1 | 2026-11-17 | [changelog/v0.2.1.md](changelog/v0.2.1.md) |
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ export GATEWAY_ADMIN_TOKEN=pick-something-long
./mvnw -pl path-gateway spring-boot:run
```

First boot seeds four providers and a starter route table. To also mint a demo key
(off by default, never in the `prod` profile), start with
First boot does **not** create providers or routes: a real deployment configures its own,
so the console starts empty instead of showing a catalogue nobody owns. For a 60-second
tour against example providers and routes, start with `GATEWAY_SEED_DEFAULTS=true`; it
only fills an empty database, and anything you delete stays deleted.

To also mint a demo key (off by default, never in the `prod` profile), add
`GATEWAY_BOOTSTRAP_DEMO_KEY=true`; it is printed once in the log:

```
Expand All @@ -82,6 +86,9 @@ curl -s http://localhost:8080/v1/chat/completions \
-d '{"model":"auto-fast","messages":[{"role":"user","content":"Say hi"}]}'
```

`auto-fast` is one of the example routes, so the call above needs `GATEWAY_SEED_DEFAULTS=true`
on that boot. With real providers, use the model ids you created in the console.

Any OpenAI SDK works — point `base_url` at `http://localhost:8080/v1`:

```python
Expand Down
45 changes: 45 additions & 0 deletions changelog/v0.2.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# v0.2.4

A small release about first-run honesty: a real deployment no longer starts with a
catalogue of providers it has no credentials for.

Until now `GATEWAY_SEED_DEFAULTS` defaulted to `true`, so the first boot of an empty
database created `openai`, `anthropic`, `groq` and `gemini` plus a starter route table.
Those rows carried no keys, so every call through them failed, and the console showed
them as if they were configured. Deleting them did not help for long: the seeder looked
each provider up by slug on every boot and recreated any that were missing.

Nothing changes for an existing database that already has providers and routes. To clear
the examples out of one that has them, follow
[`docs/OPERATIONS.md`](../docs/OPERATIONS.md#removing-the-example-catalogue).

## Changed

- **Seeding is off by default.** `GATEWAY_SEED_DEFAULTS` now defaults to `false`, and
`GatewayProperties.seedDefaults` matches it, so a fresh gateway has an empty catalogue
and the console is where providers, routes and keys are added. Set the variable to
`true` for a throwaway demo instance.
- **The example catalogue only fills an empty catalogue.** The seeder requires both the
provider and the route table to be empty, and it no longer looks providers up by slug,
so it cannot resurrect one that was deleted.
- **`deploy/dokploy/compose.yml` passes `GATEWAY_SEED_DEFAULTS` through** with a `false`
default. Docker Compose only injects a variable the compose file interpolates, so the
line in Dokploy's Environment editor never reached the process and the seeder kept
running with its built-in default.
- `README.md`, `docs/CONFIGURATION.md`, `docs/OPERATIONS.md` and
`deploy/dokploy/README.md` describe the new default, the ready-made base URLs for
ChatGPT, Gemini, OpenCode and the other common upstreams, and how to delete the example
rows from a database that already has them.

## Fixed

- A provider deleted in the console stays deleted across restarts. Previously it came back
on the next boot whenever the seed flag was on.

## Tests

- New `SeedNoResurrectionTest`: deleting an example provider and running the seeder again
leaves it deleted, and a second seed run does not duplicate rows.
- The suites that assert on the example catalogue (`GatewayApiTest`, `AliasServiceTest`,
`RoutingTest`, `PublicModelsTest`) now opt in with `gateway.seed-defaults=true` instead
of relying on the default.
33 changes: 29 additions & 4 deletions deploy/dokploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ database. The console is always a plain Application.
1. Dokploy → **Create → Compose**.
2. Source: GitHub → `an1ndra/path`, branch `main`.
3. Compose path: `deploy/dokploy/compose.yml`.
4. **Environment** (the compose file references all of these):
4. **Trigger Type: On Tag**, with auto-deploy enabled. The gateway is a production
service; a pull request or a push to `Develop` must not restart it. A release tag
(`v0.2.4`) is the only thing that deploys — see "When it deploys" below.
5. **Environment** (the compose file references all of these):

```bash
POSTGRES_PASSWORD=<openssl rand -hex 24>
Expand All @@ -27,9 +30,31 @@ GATEWAY_ADMIN_TOKEN=<openssl rand -hex 32> # only for token auth; ignore wi
GATEWAY_CORS_ORIGINS=https://admin.example.com # omit if same hostname as the console
```

5. Domain: point `gw.example.com` at port **8080**, enable HTTPS.
6. Deploy. First boot logs `Gateway ready. Admin API: enabled` and, if `-P release` was
used, seeds four providers.
The compose file passes `GATEWAY_SEED_DEFAULTS` through with a `false` default, so a fresh
database starts with an empty catalogue and the console is where providers and routes are
added. Set it to `true` only on a demo instance.

6. Domain: point `gw.example.com` at port **8080**, enable HTTPS.
7. Deploy. First boot logs `Gateway ready. Admin API: enabled`.

### When it deploys

Dokploy is set to **On Tag**, not **On Push**. The release flow is:

1. `Develop` is merged into `main` through a pull request (the required checks run there).
2. A `vX.Y.Z` tag is pushed on the merge commit.
3. The tag starts the GitHub release workflow (image scan, promotion to GHCR, release
notes) and the Dokploy webhook (rebuild from that tag and restart).

Pushes to `Develop`, pull requests and Dependabot branches therefore never touch
production; only a tag does. If a deploy should be skipped for a tag, disable auto-deploy
before pushing it.

The compose builds from the tagged source (`build: context: ../..`) rather than pulling
`:latest`. That is deliberate: both webhooks fire at the same moment, so a `:latest` pull
would race the image build and could deploy the previous release. Building the tagged
commit cannot race and guarantees the running code matches the tag. The GHCR image remains
the artifact to run elsewhere (Kubernetes, another host) and the one Trivy gates.

### Application route (external Postgres)

Expand Down
3 changes: 3 additions & 0 deletions deploy/dokploy/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ services:
SPRING_MAIL_USERNAME: ${SPRING_MAIL_USERNAME:-}
SPRING_MAIL_PASSWORD: ${SPRING_MAIL_PASSWORD:-}
GATEWAY_API_DOCS: "false"
# An empty catalogue stays empty: providers and routes come from the console, not
# from the example rows the seeder would otherwise insert on first boot.
GATEWAY_SEED_DEFAULTS: ${GATEWAY_SEED_DEFAULTS:-false}
# Provider keys are added through the console (Settings → Providers) or as
# OPENAI_API_KEY / ANTHROPIC_API_KEY / GROQ_API_KEY / GEMINI_API_KEY.
ports:
Expand Down
5 changes: 3 additions & 2 deletions docs/ADMIN-UI.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ The admin console lives in its own repository, [an1ndra/path-admin](https://gith

Read and write against this API: dashboard (spend, cache, latency, provider circuits, top
models, recent failures), providers (create/edit with a provider API key, probe, delete),
routes (create, enable/disable, delete), client keys (create with budgets and allowlists,
top up, revoke).
routes (add a model, enable/disable, delete), client keys (create with budgets and
allowlists, top up, revoke), **configuration** (the gateway switches, alert email and the
daily digest) and **settings** (the session: identity, scopes, token, sign out).

## Auth

Expand Down
45 changes: 37 additions & 8 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ except the provider credentials you actually use.
| Variable | Default | Meaning |
|---|---|---|
| `GATEWAY_BOOTSTRAP_DEMO_KEY` | `false` | create a demo key when the table is empty (ignored in `prod`) |
| `GATEWAY_SEED_DEFAULTS` | `true` | seed the example provider/route catalogue on boot; set `false` on a real deployment |
| `GATEWAY_SEED_DEFAULTS` | `false` | seed the example provider/route catalogue into an empty database (demo instances only) |
| `GATEWAY_DEFAULT_RPM` | `120` | default requests/minute for new keys |
| `GATEWAY_DEFAULT_CREDIT_USD` | unlimited | default credit limit for new keys |
| `GATEWAY_DEFAULT_MAX_CONCURRENT` | `8` | in-flight requests per key (0 = unlimited) |
Expand Down Expand Up @@ -97,33 +97,62 @@ way, so they are correct in a cluster regardless of this setting.

| Variable | Meaning |
|---|---|
| `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` / `GROQ_API_KEY` / `GEMINI_API_KEY` | credentials for the seeded providers |
| `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` / `GROQ_API_KEY` / `GEMINI_API_KEY` | credentials for the providers with those slugs |
| `GATEWAY_UPSTREAM_<SLUG>_KEY` | credential for any other provider slug (e.g. `GATEWAY_UPSTREAM_TOGETHER_KEY`) |

Resolution order: **database → `application.yml` → environment**. A key stored through
the admin API silently wins over the environment, which makes rotation possible without
a restart. Credentials in the database are AES-GCM encrypted with a key from
`GATEWAY_MASTER_KEY` or the generated `./data/master.key` (0600).

A provider row must exist before its environment variable is read; `openai`, `anthropic`,
`groq` and `gemini` are seeded.
A provider row must exist before its environment variable is read. Nothing is seeded by
default any more, so create the provider once (console or `POST /admin/providers`) and the
well-known variable for that slug takes over on the next boot. The four conventional slugs
are `openai`, `anthropic`, `groq` and `gemini`; anything else uses
`GATEWAY_UPSTREAM_<SLUG>_KEY`.

To see the example catalogue on a throwaway instance, set `GATEWAY_SEED_DEFAULTS=true`.
It only fills an empty catalogue, and a provider deleted later stays deleted.

### Common upstreams

Ready-made values for the providers most people add first. Everything here is an
`OPENAI`-type row except Gemini native and Vertex:

| Provider | Slug | Type | Base URL |
|---|---|---|---|
| ChatGPT / OpenAI | `openai` | `OPENAI` | `https://api.openai.com/v1` |
| Gemini (OpenAI-compatible) | `gemini` | `OPENAI` | `https://generativelanguage.googleapis.com/v1beta/openai` |
| Gemini native (AI Studio) | `gemini-native` | `GEMINI` | `https://generativelanguage.googleapis.com/v1beta` |
| OpenCode | `opencode` | `OPENAI` | `https://opencode.ai/inference/openai/v1` |
| OpenCode Go | `opencode-go` | `OPENAI` | `https://opencode.ai/inference/go/openai/v1` |
| Anthropic | `anthropic` | `ANTHROPIC` | `https://api.anthropic.com/v1` |
| Groq | `groq` | `OPENAI` | `https://api.groq.com/openai/v1` |

For a slug not in this table the credential variable is `GATEWAY_UPSTREAM_<SLUG>_KEY`
(OpenCode uses `OPENCODE_API_KEY` by convention, so set
`GATEWAY_UPSTREAM_OPENCODE_KEY` or paste the key into the console).

Each route needs the upstream model id and a price per million tokens; a `0.00` price
records usage but never charges it. `POST /admin/models/sync` imports a provider's list
and prices only ids in its built-in table, so check anything it leaves at `0.00`.

### Gemini

Gemini is seeded as an `OPENAI`-type provider pointing at Google's
OpenAI-compatible endpoint:
Google exposes an OpenAI-compatible endpoint, so a plain `OPENAI`-type provider works:

```
base_url = https://generativelanguage.googleapis.com/v1beta/openai
```

Set `GEMINI_API_KEY` and add a route per model you want to expose; the upstream id is
Create that provider (console → Providers → Add, or `POST /admin/providers`), set
`GEMINI_API_KEY`, and add a route per model you want to expose; the upstream id is
whatever Gemini calls it (`gemini-2.5-flash`, `gemini-3-flash`, …):

```bash
A='X-Admin-Token: ...'
curl -s -X POST localhost:8080/admin/routes -H "$A" -H 'Content-Type: application/json' \
-d '{"public_model_id":"gemini-2.5-flash","provider_id":4,
-d '{"public_model_id":"gemini-2.5-flash","provider_id":<gemini-provider-id>,
"upstream_model_id":"gemini-2.5-flash",
"input_price_per_million":0.30,"output_price_per_million":2.50,
"priority":10}'
Expand Down
30 changes: 30 additions & 0 deletions docs/OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ curl -s -X POST localhost:8080/admin/keys/1/revoke -H "$A"
curl -s -X POST localhost:8080/admin/models/sync -H "$A"
```

## Removing the example catalogue

`GATEWAY_SEED_DEFAULTS=true` creates four providers (`openai`, `anthropic`, `groq`,
`gemini`), a starter route table and, with `GATEWAY_BOOTSTRAP_DEMO_KEY`, a `demo-local`
key. They carry no credentials, so they show up in the console as rows you cannot call.
Deleting them in the console is enough — the seeder no longer recreates a deleted provider
on the next boot. From a shell:

```bash
A='X-Admin-Token: pick-something-long'

# what is there, and whether the credential actually resolves
curl -s localhost:8080/admin/providers -H "$A" \
| jq -r '.[] | [.id, .slug, (.credential_configured|tostring)] | @tsv'

# delete each example provider; its routes cascade with it
for id in 1 2 3 4; do
curl -s -X DELETE "localhost:8080/admin/providers/$id" -H "$A"; echo
done

# revoke the demo key if it was created
curl -s localhost:8080/admin/keys -H "$A" \
| jq -r '.[] | select(.name == "demo-local") | .id' \
| xargs -r -I{} curl -s -X POST "localhost:8080/admin/keys/{}/revoke" -H "$A"
```

Then set `GATEWAY_SEED_DEFAULTS=false` in the deployment and restart, so a fresh database
is not filled again. Usage rows already written by the examples are history, not
configuration; leave them or delete them with the retention job.

## Projects and admin tokens

Projects group keys and usage. Admin tokens carry `read` or `read,write`; the bootstrap
Expand Down
2 changes: 1 addition & 1 deletion docs/SPRING-AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on Spring AI; the gateway never depends on it.
<dependency>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-spring-ai</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
</dependency>
```

Expand Down
7 changes: 6 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ admin surface and metering.

```bash
python3 tools/mock-upstream.py 9099 &
GATEWAY_ADMIN_TOKEN=test-admin java -jar path-gateway/target/path-0.2.2.jar &
GATEWAY_ADMIN_TOKEN=test-admin GATEWAY_SEED_DEFAULTS=true \
java -jar path-gateway/target/path-0.2.2.jar &
python3 tools/smoke_test.py
```

The suite calls the example catalogue by name (`gpt-4o-mini`, `claude-3.5-haiku`,
`auto-fast`, …), so it needs `GATEWAY_SEED_DEFAULTS=true` against a clean database. That
flag is off by default for real deployments; CI sets it for this job.

The mock switches behaviour by model id, which is how failure paths are tested:

| Model id contains | Behaviour |
Expand Down
2 changes: 1 addition & 1 deletion path-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.github.an1ndra</groupId>
<artifactId>path-parent</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ public class GatewayProperties {
private boolean bootstrapDemoKey = false;

/**
* Seed the example provider/route catalogue on boot. A real deployment wants this off:
* otherwise four providers nobody configured reappear on every restart.
* Seed the example provider/route catalogue on boot. Off by default: a real deployment
* configures its own providers, and the examples would otherwise reappear on every
* restart. Only a throwaway demo instance sets this.
*/
private boolean seedDefaults = true;
private boolean seedDefaults = false;

private int defaultRpmLimit = 120;

Expand Down
30 changes: 17 additions & 13 deletions path-gateway/src/main/java/com/anindra/path/seed/DataSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public class DataSeeder implements ApplicationRunner {
@Override
@Transactional
public void run(ApplicationArguments args) {
boolean fresh = providers.count() == 0;
// Seed only into a completely empty catalogue. Creating providers by slug on every
// boot would resurrect one an operator deleted on purpose, which is exactly the
// "dummy data keeps coming back" complaint.
boolean fresh = providers.count() == 0 && routes.count() == 0;
if (props.isSeedDefaults()) {
Map<String, Provider> bySlug = ensureProviders();
if (fresh && routes.count() == 0) {
seedRoutes(bySlug);
if (fresh) {
seedRoutes(createExampleProviders());
} else {
log.info("Gateway already has providers/routes: not adding the example catalogue.");
}
} else {
log.info("Gateway seed-defaults is off: not creating the example provider/route catalogue.");
Expand All @@ -71,17 +75,17 @@ public void run(ApplicationArguments args) {
: "enabled (send X-Admin-Token)");
}

private Map<String, Provider> ensureProviders() {
private Map<String, Provider> createExampleProviders() {
Map<String, Provider> bySlug = new LinkedHashMap<>();
bySlug.put("openai", providers.findBySlug("openai").orElseGet(() -> providers.save(
new Provider("openai", "OpenAI", ProviderType.OPENAI, "https://api.openai.com/v1"))));
bySlug.put("anthropic", providers.findBySlug("anthropic").orElseGet(() -> providers.save(
new Provider("anthropic", "Anthropic", ProviderType.ANTHROPIC, "https://api.anthropic.com/v1"))));
bySlug.put("groq", providers.findBySlug("groq").orElseGet(() -> providers.save(
new Provider("groq", "Groq", ProviderType.OPENAI, "https://api.groq.com/openai/v1"))));
bySlug.put("gemini", providers.findBySlug("gemini").orElseGet(() -> providers.save(
bySlug.put("openai", providers.save(
new Provider("openai", "OpenAI", ProviderType.OPENAI, "https://api.openai.com/v1")));
bySlug.put("anthropic", providers.save(
new Provider("anthropic", "Anthropic", ProviderType.ANTHROPIC, "https://api.anthropic.com/v1")));
bySlug.put("groq", providers.save(
new Provider("groq", "Groq", ProviderType.OPENAI, "https://api.groq.com/openai/v1")));
bySlug.put("gemini", providers.save(
new Provider("gemini", "Google Gemini", ProviderType.OPENAI,
"https://generativelanguage.googleapis.com/v1beta/openai"))));
"https://generativelanguage.googleapis.com/v1beta/openai")));
return bySlug;
}

Expand Down
Loading
Loading