> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Compute Client

> Create and configure a TypeScript SDK client for Namespace compute instances.

Use `createComputeClient()` to configure authentication and select the regional API endpoint. The returned client provides access to the compute services: instances, commands, storage, usage, observability, and management.

## `createComputeClient()`

Create a client for the compute services. The client loads credentials when it first makes an authenticated request.

<h3 id="createcomputeclient-example">
  Example
</h3>

```typescript {3} theme={null}
import { createComputeClient } from "@namespacelabs/sdk/api/compute";

const client = createComputeClient();

/*  Work with the compute client here */
```

Select another region or provide an explicit token source:

```typescript {4-7} theme={null}
import { loadUserToken } from "@namespacelabs/sdk/auth";
import { createComputeClient } from "@namespacelabs/sdk/api/compute";

const client = createComputeClient({
  region: "eu",
  tokenSource: loadUserToken,
});
```

<h3 id="createcomputeclient-api-reference">
  API reference
</h3>

```typescript theme={null}
createComputeClient(opts?: ComputeClientOpts): ComputeClient
```

<h4 id="createcomputeclient-arguments-and-options">
  Arguments and options
</h4>

<ResponseField name="opts" type="ComputeClientOpts">
  Options used to configure the client.

  <Expandable title="properties" defaultOpen>
    <ResponseField name="tokenSource" type="TokenSourceInput">
      Provides API tokens for Namespace requests. Defaults to the Namespace workload token when available, then falls back to the local user token.
    </ResponseField>

    <ResponseField name="region" type="string" default="us">
      The regional API endpoint used by the default transport, such as `us` or `eu`. The client connects to `https://<region>.compute.namespaceapis.com`.
    </ResponseField>

    <ResponseField name="transport" type="Transport">
      A fully configured Connect transport for compute API requests. When provided, `region` and `tokenSource` are ignored, so the transport must supply its own authentication.
    </ResponseField>
  </Expandable>
</ResponseField>

<h4 id="createcomputeclient-return-value">
  Return value
</h4>

`createComputeClient()` returns a [`ComputeClient`](#computeclient). In examples, this object is assigned to the `client` variable.

***

## `ComputeClient`

A `ComputeClient` exposes one service client per compute API. All six share the transport created with the client, so they use the same region and credentials.

<h3 id="computeclient-example">
  Example
</h3>

```typescript {4} theme={null}
import { createComputeClient } from "@namespacelabs/sdk/api/compute";

const client = createComputeClient();
const instances = await client.compute.listInstances({});
```

<h3 id="computeclient-api-reference">
  API reference
</h3>

```typescript theme={null}
interface ComputeClient {
  compute: Client<typeof ComputeService>;
  command: Client<typeof CommandService>;
  storage: Client<typeof StorageService>;
  usage: Client<typeof UsageService>;
  observability: Client<typeof ObservabilityService>;
  management: Client<typeof ManagementService>;
}
```

Each service client exposes its RPCs as camelCase methods. The table below lists what each service covers.

| Property                                                                  | Covers                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`client.compute`](/docs/reference/typescript-sdk/compute/manage)              | The [instance lifecycle](/docs/reference/typescript-sdk/compute/manage), and [access and networking](/docs/reference/typescript-sdk/compute/access) for ingresses, SSH, VNC, Kubernetes, and workspace network configuration.                                                                                                         |
| [`client.command`](/docs/reference/typescript-sdk/compute/command)             | Running commands on an instance with `runCommand` and `runCommandSync`.                                                                                                                                                                                                                                                     |
| [`client.storage`](/docs/reference/typescript-sdk/compute/storage)             | Cache volumes and persistent volumes, including listing, describing, and destroying volumes and snapshots.                                                                                                                                                                                                                  |
| [`client.usage`](/docs/reference/typescript-sdk/compute/usage)                 | Usage reporting with `getUsage`, `getVolumeUsage`, `getArtifactUsage`, `getUsageTimeSeries`, `getConcurrency`, and `generateReport`.                                                                                                                                                                                        |
| [`client.observability`](/docs/reference/typescript-sdk/compute/observability) | Instance logs with `streamInstanceLogs` and `fetchInstanceLogs`, and egress records with `fetchInstanceEgress`.                                                                                                                                                                                                             |
| `client.management`                                                       | Partner-only. Registers and reads the known images Namespace optimizes for fast boot, with `setKnownImages` and `getKnownImages`. These methods require a partner OIDC token trusted by Namespace, not the user or workload credentials described under [Authentication](/docs/reference/typescript-sdk/compute/authentication). |

Request and response types for every method are documented in the [compute API reference](https://buf.build/namespace/cloud/docs/main:namespace.cloud.compute.v1beta).

These pages cover the methods most applications need. The service clients expose every generated RPC, including internal ones such as `optimizeImage`, so use the generated API reference for anything not documented here.

<Info>
  `ComputeClient` has no `close()` method.
</Info>

### Explore the APIs

<Columns cols={2}>
  <Card title="Create and manage instances" icon="server" href="/docs/reference/typescript-sdk/compute/manage">
    Create, wait for, inspect, list, extend, suspend, wake, and destroy instances.
  </Card>

  <Card title="Access and networking" icon="radio-tower" href="/docs/reference/typescript-sdk/compute/access">
    Expose ingresses and read SSH, VNC, and Kubernetes configuration.
  </Card>

  <Card title="Authenticate with Namespace" icon="key" href="/docs/reference/typescript-sdk/compute/authentication">
    Configure credentials for local development and automated workloads.
  </Card>
</Columns>

## Related documentation

<Columns cols={2}>
  <Card title="Get started with Compute" icon="rocket" href="/docs/reference/typescript-sdk/compute">
    Create your first instance with the TypeScript SDK.
  </Card>

  <Card title="Compute platform" icon="microchip" href="/docs/architecture/compute">
    Learn about platforms, machine shapes, storage, and instance access.
  </Card>
</Columns>
