TypeScript quickstart
Call the /platform/v1 Infrastructure API with the generated @forestvpn/console-api TypeScript client.
@forestvpn/console-api is the generated TypeScript client for the
/platform/v1 plane — typed request/response models straight from the same
OpenAPI document that renders the API reference.
Honest distribution note: the package is not published to npm yet. It
lives at packages/forestvpn/console-api in the ForestVPN repository as a
pnpm workspace package — you consume it from inside a checkout.
Prerequisites
- Node.js 20+ and pnpm
- A checkout of the ForestVPN repository,
pnpm installrun at its root - A project API key (
fvpn_v1_…) — see API keys
1. Add the workspace dependency
Inside the checkout's workspace, depend on the package with the workspace protocol:
{
"dependencies": {
"@forestvpn/console-api": "workspace:*"
}
}2. Build the client's dist
Apps resolve the package's built dist/, so build it once (and after every
spec regeneration) with the package-local TypeScript compiler:
pnpm -C packages/forestvpn/console-api build3. First call: list your API keys
import { Configuration, PlatformApiKeysApi } from "@forestvpn/console-api";
// Authenticate with a project API key (fvpn_v1_…) minted in the console.
// The key is project-bound: it only authenticates inside its own project.
export async function listApiKeys(apiKey: string, projectId: string) {
const api = new PlatformApiKeysApi(
new Configuration({
basePath: "https://api.fvpn.net",
accessToken: apiKey,
}),
);
const { data: keys } = await api.listPlatformApiKeys(projectId);
for (const key of keys) {
console.log(
`${key.name} (${key.key_prefix}) last used: ${key.last_used_at ?? "never"}`,
);
}
return keys;
}Two things to notice:
- Auth is just the key.
accessTokensendsAuthorization: Bearer fvpn_v1_…; no cookies, no session. - The project id is explicit. Every
/platform/v1operation takes the project UUID as its first argument (sent as theX-Project-Idheader). The key itself is project-bound, so the two must agree — a mismatch is a401.
4. Run
Call it with your key and project id — for example from a tiny entry file
executed with tsx or compiled with tsc:
import { listApiKeys } from "./first-call";
await listApiKeys(process.env.FVPN_API_KEY!, process.env.FVPN_PROJECT_ID!);Expected output: one line per key — name, display prefix, and when it last authenticated a request.
Verified by
scripts/quickstart-verify/ts-client.sh — builds the package dist and
typechecks this page's snippet against the real package on every CI run.