Manage a project from code
Create environments, their keys and their gateway settings with a project key, and read the project's audit log and costs.
Everything you can do in the dashboard for a project and its environments, you can also do through the management API with a project key: set up a new environment, give it keys, turn on wallets or BYOK, set limits, and read what changed and what it cost. This page walks through it. What stays in the dashboard is the organization itself, its members, creating a project, and the project's first key (see Authentication).
Get a project key#
In the dashboard, a person who may change the project creates the first project key: Settings (at the foot of the main sidebar) › Project › Project keys, with a name, the role Admin and, optionally, an expiry. Store its secret, shown once:
export HIXEL_PROJECT_KEY="hx_proj_…"From then on, that key can create more (a read-only member key for a reporting job, for
example):
curl https://api.hixel.dev/v1/project/keys \
-H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Reporting", "role": "member" }'const { key, secret } = await hixel.projectKeys.create({ name: "Reporting", role: "member" });
console.log(key.id, secret); // the secret is shown only nowGET /v1/project/keys lists them, PATCH /v1/project/keys/{id} renames one or changes its
expiry, POST /v1/project/keys/{id}/rotate replaces its secret (keeping the old one working for
grace_period_seconds if you like), POST /v1/project/keys/{id}/revoke revokes one, and
GET /v1/project / PATCH /v1/project read and rename the project.
Create an environment#
Every project has one live environment, Production, and any number of test ones. Add a test environment with a name and a slug:
curl https://api.hixel.dev/v1/environments \
-H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
-H "Content-Type: application/json" \
-d '{ "name": "Preview", "slug": "preview" }'const environment = await hixel.environments.create({ name: "Preview", slug: "preview" });
console.log(environment.id, environment.kind); // "env_…", "test"GET /v1/environments lists the project's environments (Production first), PATCH /v1/environments/{id} renames one, and POST /v1/environments/{id}/archive archives a test
environment for good: it keeps its data and serves no traffic. Production cannot be archived on
its own (409 live_environment).
Give it keys#
Every environment endpoint takes the project key with the environment named in
x-hixel-environment. Create the environment's own keys that way: one for your servers' inference
traffic, one for your backend's management calls.
curl https://api.hixel.dev/v1/keys \
-H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
-H "x-hixel-environment: env_k3j9x2m8q1w7e4r5t6y0u2i3" \
-H "Content-Type: application/json" \
-d '{ "name": "Inference", "scopes": ["inference"] }'const preview = hixel.environment("env_k3j9x2m8q1w7e4r5t6y0u2i3");
const inference = await preview.keys.create({ name: "Inference", scopes: ["inference"] });
const management = await preview.keys.create({ name: "Backend", scopes: ["management"] });
console.log(inference.secret, management.secret); // each shown only nowConfigure the gateway#
An environment's gateway settings change with PATCH /v1/gateway, which takes a project key with
the admin role (an environment's own key may read them, never change them). Each field you send
changes; each policy you send (limits, wallet, routing, guardrails, cache) replaces that
whole policy, in the same shape GET /v1/gateway returns.
curl -X PATCH https://api.hixel.dev/v1/gateway \
-H "Authorization: Bearer $HIXEL_PROJECT_KEY" \
-H "x-hixel-environment: env_k3j9x2m8q1w7e4r5t6y0u2i3" \
-H "Content-Type: application/json" \
-d '{
"require_customer": true,
"allowed_models": ["claude-sonnet-5-5", "claude-haiku-5-5", "gpt-6.2-sol"],
"wallet": { "enabled": true },
"byok": { "enabled": true, "providers": ["openai", "anthropic"] },
"limits": {
"customer": {
"rate": { "requests_per_minute": 120 },
"spend": [{ "id": "monthly", "window": "month", "limit_micros": "100000000" }]
},
"member": { "spend": [{ "id": "daily", "window": "day", "limit_micros": "5000000" }] }
}
}'const settings = await hixel.environment("env_k3j9x2m8q1w7e4r5t6y0u2i3").gateway.update({
require_customer: true,
allowed_models: ["claude-sonnet-5-5", "claude-haiku-5-5", "gpt-6.2-sol"],
wallet: { enabled: true },
byok: { enabled: true, providers: ["openai", "anthropic"] },
limits: {
customer: {
rate: { requests_per_minute: 120 },
spend: [{ id: "monthly", window: "month", limit_micros: "100000000" }],
},
member: { spend: [{ id: "daily", window: "day", limit_micros: "5000000" }] },
},
});
console.log(settings.revision);| Field | What it sets |
|---|---|
require_customer | Every request must name a customer (Sending requests) |
markup_bps | Your markup on provider cost, in basis points (Models) |
allowed_models | The environment's model allowlist; null allows every model of the catalog |
aliases | Your own model aliases, replacing every alias |
byok | enabled, providers, fallback_to_platform_key (Customer provider keys) |
params | drop_unsupported: drop parameters a provider does not support rather than refuse the request |
wallet | enabled: pay customers' requests from their wallets (Wallets) |
limits | Rate and spend limits of every customer, member and key (Limits) |
routing, guardrails, cache | Retries and timeouts, content rules, and the response cache |
A field out of bounds is 400 invalid_request, with its path in param
(limits.customer.spend.0.limit_micros). The change reaches the gateway within moments; the
answer is the environment's new settings, with its revision.
Read the audit log#
Every change to the project and its environments, by a person in the dashboard or by a key through the API, is in the project's audit log, newest first:
curl "https://api.hixel.dev/v1/audit_log?limit=20" \
-H "Authorization: Bearer $HIXEL_PROJECT_KEY"for await (const entry of hixel.auditLog.list({ limit: 20 })) {
console.log(entry.created_at, entry.action, entry.target_type, entry.target_id);
}Each entry names who did it (actor: a person, or a key by its id), what (action), and on what
(target_type, target_id). The organization's own changes (its settings, members, invitations)
are not in a project's log.
Read what the project costs#
With the admin role, GET /v1/billing/summary?from=…&to=… sums what the project's usage cost
your organization over a range of at most 92 days, in all, by environment and by day.
GET /v1/billing/standings lists whether each environment's traffic is let through, a page of
{id, name, kind, standing}.
Related#
- Authentication: both kinds of key, and which you need for what.
- API reference: every project and environment operation.
- Node.js SDK: one client per environment from a project key.