# JavaScript / TypeScript SDK

Source : https://webgune.cloud/en-us/docs/sdk-js · Mis à jour le 2026-10-27

# JavaScript / TypeScript SDK

`@webgune/sdk` is the official client for controlling your webgune account from code. It is a typed alternative to raw `fetch` calls against the [REST API](/docs/reference-api).

## Installation

```bash
npm install @webgune/sdk
```

## Usage

```ts
import { createClient } from "@webgune/sdk";

const webgune = createClient({ apiKey: process.env.WEBGUNE_API_KEY! });

const projects = await webgune.projects.list();
await webgune.services.redeploy("svc_123");
```

The API key is created from **Dashboard → Developers → API keys** (see [API keys](/docs/cles-api)). Give the key one scope per resource used (`projects`, `services`, `domains`, `billing`, `dashboard`, `apikeys`, `reseller`), in the format `resource:read` or `resource:write`.

## Covered resources

```text
webgune.projects   list · get · create · update · remove
webgune.services   listByProject · get · create · remove · redeploy
                    logs · metrics · getEnv · setEnv · scale
                    deployments · rollback
webgune.domains    check · list · register · get · remove
                    listDns · addDns · removeDns
webgune.billing    plans · subscription · invoices
webgune.dashboard  stats · deploymentHistory
webgune.apiKeys    list · create · revoke · auditLog
webgune.reseller   organization · subClients · overview
```

An endpoint not yet covered by a wrapper remains accessible via `webgune.raw`, the fully typed underlying [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) client:

```ts
const { data } = await webgune.raw.GET("/services/{id}/k8s-status", {
  params: { path: { id: "svc_123" } },
});
```

## Error handling

Any non-2xx response throws a `WebguneApiError` (`status`, `code`, `message`) instead of silently returning an incorrect value:

```ts
import { WebguneApiError } from "@webgune/sdk";

try {
  await webgune.services.redeploy("id-inexistant");
} catch (err) {
  if (err instanceof WebguneApiError && err.status === 404) {
    console.error("Service not found");
  }
}
```

## Generated types

TypeScript types are generated automatically from the API's [OpenAPI spec](/api/v1/openapi.json). They always reflect what the API accepts and returns, with no manual maintenance. Without an installed package, the [interactive reference](/developers/api-reference) shows the same schemas directly in the browser.
