# API

You can interact with the Container Builds API through Connect RPC clients for Node.js and Go:

- **Node.js SDK**: [`@depot/sdk-node`](https://github.com/depot/sdk-node) for TypeScript and JavaScript projects
- **Go clients**: [generated Connect and protobuf packages](https://buf.build/depot/api) from the `depot/api` Buf module, plus [`depot/depot-go`](https://github.com/depot/depot-go) helpers for build and BuildKit lifecycles

The clients provide access to project, organization, build, registry, BuildKit, and usage services.

## API services

The Depot API includes the following services. Access each service through the SDKs using the methods listed below:

### Project service

[`depot.core.v1.ProjectService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.ProjectService)

- `ListProjects` \- List all projects for an organization
- `GetProject` \- Get details for a specific project
- `CreateProject` \- Create a new project
- `UpdateProject` \- Update a project's configuration
- `DeleteProject` \- Delete a project
- `ResetProject` \- Reset a project (terminates all machines and deletes all cached data)
- `ListTrustPolicies` \- List trust policies for a project
- `AddTrustPolicy` \- Add a trust policy to a project
- `RemoveTrustPolicy` \- Remove a trust policy from a project
- `ListTokens` \- List all tokens for a project
- `CreateToken` \- Create a new project token
- `UpdateToken` \- Update a project token
- `DeleteToken` \- Delete a project token

### Build execution service

[`depot.build.v1.BuildService`](https://buf.build/depot/api/docs/main:depot.build.v1#depot.build.v1.BuildService)

- `CreateBuild` \- Create a new build
- `FinishBuild` \- Mark a build as finished
- `GetBuildSteps` \- Get the steps for a build
- `GetBuildStepLogs` \- Get logs for a specific build step

### Registry service

[`depot.build.v1.RegistryService`](https://buf.build/depot/api/docs/main:depot.build.v1#depot.build.v1.RegistryService)

- `ListImages` \- List all images in a project's registry
- `DeleteImage` \- Delete images from a project's registry

### Registry retention service

[`depot.registry.v1beta1.RegistryService`](https://buf.build/depot/api/docs/main:depot.registry.v1beta1#depot.registry.v1beta1.RegistryService)

- `GetRetentionPolicy` \- Read the explicit policy for a repository or organization default
- `UpsertRetentionPolicy` \- Set a count-based or time-based retention policy
- `DeleteRetentionPolicy` \- Remove an explicit policy

See [Manage Registry retention policies](/content/docs/api/sdk-reference#manage-registry-retention-policies/index.html) for Node.js and Go examples.

### Build records service

[`depot.core.v1.BuildService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.BuildService)

- `ShareBuild` \- Create a public share URL for a build
- `StopSharingBuild` \- Disable public sharing for a build
- `ListBuilds` \- List builds for a project
- `GetBuild` \- Get metadata for a build

### Organization service

[`depot.core.v1.OrganizationService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.OrganizationService)

- `ListOrganizations` \- List organizations available to the authenticated user

### BuildKit service

[`depot.buildkit.v1.BuildKitService`](https://buf.build/depot/api/docs/main:depot.buildkit.v1#depot.buildkit.v1.BuildKitService)

- `GetEndpoint` \- Get a BuildKit endpoint for a build
- `ReportHealth` \- Report the health status of a build
- `ReleaseEndpoint` \- Release a BuildKit endpoint

### Usage service

[`depot.core.v1.UsageService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.UsageService)

- `ListProjectUsage` \- List usage data for projects
- `GetProjectUsage` \- Get usage data for a specific project
- `GetUsage` \- Get detailed usage data over a specified period

## Project service

Docs: [`depot.core.v1.ProjectService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.ProjectService)

A project is an isolated cache. Projects belong to a single organization and are never shared. They represent the layer cache associated with the images built inside of it; you can build multiple images for different platforms with a single project. Or you can choose to have one project per image built.

When you want to segregate your customer builds from one another, we recommend one project per customer.

### List projects for an organization

You can list all of the projects for your org with an empty request payload.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.listProjects({}, {headers})

console.log(result.projects)
```

### Create a project

To create a project, you need to pass a request that contains the name of the project, the id of your organization, the region you want to create the project in, and the cache volume size you want to use with the project.

Supported regions:

- `us-east-1`
- `eu-central-1`

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.createProject(
  {
    name: 'my-project',
    organizationId: 'org-id',
    regionId: 'us-east-1',
    cachePolicy: {keepGb: 50, keepDays: 14},
  },
  {headers},
)

console.log(result.project)
```

### Get a project

To get a project, you need to pass the ID of the project you want to get.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.getProject({projectId: 'project-id'}, {headers})

console.log(result.project)
```

### Update a project

To update a project, you can pass the ID of the project you want to update and the fields you want to update.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.updateProject(
  {
    projectId: 'project-id',
    name: 'my-project',
    regionId: 'us-east-1',
    cachePolicy: {keepGb: 50, keepDays: 14},
  },
  {headers},
)

console.log(result.project)
```

### Delete a project

You can delete a project by ID. This will destroy any underlying volumes associated with the project.

Node.js SDKGo SDK

```javascript
await depot.core.v1.ProjectService.deleteProject({projectId: 'project-id'}, {headers})
```

### Reset a project

Resetting a project terminates its active build machines and permanently deletes its cached build data. The project itself and its configuration remain available.

Node.js SDKGo SDK

```javascript
await depot.core.v1.ProjectService.resetProject({projectId: 'project-id'}, {headers})
```

### List tokens for a project

You can list the tokens for a project by ID.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.listTokens({projectId: 'project-id'}, {headers})
```

### Create a project token

You can create a token for a given project ID.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.createToken(
  {
    projectId: 'project-id',
    description: 'my-token',
  },
  {headers},
)
```

### Update a project token

You can update a project token by ID.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.ProjectService.updateToken(
  {
    tokenId: 'token-id',
    description: 'new-description',
  },
  {headers},
)
```

### Delete a project token

You can delete a project token by ID.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

await depot.core.v1.ProjectService.deleteToken({tokenId: 'token-id'}, {headers})
```

### List trust policies for a project

Node.js SDKGo SDK

```javascript
const policies = await depot.core.v1.ProjectService.listTrustPolicies({projectId: 'project-id'}, {headers})
```

### Add a trust policy for a project

Node.js SDKGo SDK

```javascript
// GitHub
await depot.core.v1.ProjectService.addTrustPolicy(
  {
    projectId: 'project-id',
    provider: {
      case: 'github',
      value: {
        repositoryOwner: 'org',
        repository: 'repo',
      },
    },
  },
  {headers},
)
```

```javascript
// BuildKite
await depot.core.v1.ProjectService.addTrustPolicy(
  {
    projectId: 'project-id',
    provider: {
      case: 'buildkite',
      value: {
        organizationSlug: 'org',
        pipelineSlug: 'pipeline',
      },
    },
  },
  {headers},
)
```

```javascript
// CircleCI
await depot.core.v1.ProjectService.addTrustPolicy(
  {
    projectId: 'project-id',
    provider: {
      case: 'circleci',
      value: {
        organizationUuid: 'uuid',
        projectUuid: 'uuid',
      },
    },
  },
  {headers},
)
```

`@depot/sdk-node@2.0.0` does not include the GitLab provider. Use Connect JSON to add a GitLab trust policy:

```javascript
const response = await fetch('https://api.depot.dev/depot.core.v1.ProjectService/AddTrustPolicy', {
  method: 'POST',
  headers: {...headers, 'Content-Type': 'application/json', 'Connect-Protocol-Version': '1'},
  body: JSON.stringify({
    projectId: 'project-id',
    gitlab: {namespaceId: 'namespace-id', projectId: 'gitlab-project-id'},
  }),
})
if (!response.ok) throw new Error(await response.text())
```

### Remove a trust policy for a project

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

await depot.core.v1.ProjectService.removeTrustPolicy({projectId: 'project-id', trustPolicyId: 'policy-id'}, {headers})
```

## Build records service

Docs: [`depot.core.v1.BuildService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.BuildService)

This service reads build metadata and controls public build sharing. It is separate from `depot.build.v1.BuildService`, which creates and finishes builds.

For the Go examples, create a client once. Each request below adds the authorization header:

```go
client := corev1connect.NewBuildServiceClient(http.DefaultClient, "https://api.depot.dev")
```

### Share a build

Create a public URL for a build. Calling the method again returns the existing share URL.

Node.js SDKGo SDK

```javascript
const result = await depot.core.v1.BuildService.shareBuild({buildId: 'build-id'}, {headers})
console.log(result.shareUrl)
```

### Stop sharing a build

Disable the public share URL for a build.

Node.js SDKGo SDK

```javascript
await depot.core.v1.BuildService.stopSharingBuild({buildId: 'build-id'}, {headers})
```

### List builds

List build metadata for a project. Use `nextPageToken` from a response to request the next page.

Node.js SDKGo SDK

```javascript
const result = await depot.core.v1.BuildService.listBuilds(
  {projectId: 'project-id', pageSize: 100, pageToken: undefined},
  {headers},
)
console.log(result.builds, result.nextPageToken)
```

### Get build metadata

Get the status, timestamps, duration, and cache-step counts for one build.

Node.js SDKGo SDK

```javascript
const result = await depot.core.v1.BuildService.getBuild({buildId: 'build-id'}, {headers})
console.log(result.build)
```

## Organization service

Docs: [`depot.core.v1.OrganizationService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.OrganizationService)

### List organizations

List the organizations available to the authenticated user or token.

Node.js SDKGo SDK

```javascript
const result = await depot.core.v1.OrganizationService.listOrganizations({}, {headers})
console.log(result.organizations)
```

## Build execution service

Docs: [`depot.build.v1.BuildService`](https://buf.build/depot/api/docs/main:depot.build.v1#depot.build.v1.BuildService)

A build is a single image build within a given project. Once you create a build for a project, you get back an ID to reference it and a token for authentication.

### Create a build

To create a build, you need to pass a request that contains the ID of the project you want to build in.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.build.v1.BuildService.createBuild({projectId: 'project-id'}, {headers})

console.log(result.buildId)
console.log(result.buildToken)
```

#### Using the build id & token

If you're not managing the build context yourself in code via `buildx`, you can use the Depot CLI to build a given `Dockerfile` as we wrap `buildx` inside our CLI. With a build created via our API, you pass along the project, build ID, and token as environment variables:

```bash
depot build -f Dockerfile
```

**Note:** Build IDs are unique identifiers generated by Depot when creating a build via the API. When you set the `DEPOT_BUILD_ID` environment variable, `depot build` uses the existing build instead of creating a new one. If a build with that ID doesn't exist, the command will error.

### Finish a build

**Note:** You only need to do this if you're managing the build context yourself in code via `buildx`.

To mark a build as finished and clean up the underlying BuildKit endpoint, you need to pass the ID of the build you want to finish and the error result if there was one.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

await depot.build.v1.BuildService.finishBuild(
  {buildId: 'build-id', result: {case: 'error', value: {error: 'error message'}}},
  {headers},
)
```

### List the steps for a build

To list the steps for a build, you need to pass the build ID, the project ID, the number of steps to page, and an optional page token returned from a previous API call.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.build.v1.BuildService.getBuildSteps(
  {
    buildId: 'build-id',
    projectId: 'project-id',
    pageSize: 100,
    pageToken: 'page-token',
  },
  {headers},
)
```

### Get the logs for a build step

To get the logs for a build step, you need to pass the build ID, the project ID, and the build step's digest. You can also pass the number of lines to page and an optional page token returned from a previous API call.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}
const result = await depot.build.v1.BuildService.getBuildStepLogs(
  {
    buildId: 'build-id',
    projectId: 'project-id',
    buildStepDigest: 'step-digest',
    pageSize: 100,
    pageToken: 'page-token',
  },
  {headers},
)
```

## Manage Registry retention policies

Use `depot.registry.v1beta1.RegistryService` to configure image retention during automated repository provisioning. Authenticate with an [organization token](/content/docs/api/authentication/index.html). The token determines the organization; you don't need an organization ID or `x-depot-org` header. Project tokens and Registry pull/push tokens don't authorize these management operations.

Set `repository` to a repository path such as `team/app`, without a registry host or organization prefix. Use `**` for the organization-default policy. Set exactly one positive integer strategy:

- `keepCount` in Node.js or `KeepCount` in Go: retain the most recent 1 to 1000 images.
- `keepDays` in Node.js or `KeepDays` in Go: retain images for 1 to 30 days from when they were pushed.

Sending both strategies, neither strategy, or a value outside these ranges returns `InvalidArgument`. The `enabled` field isn't a switch for disabling retention. Use `DeleteRetentionPolicy` to remove an explicit policy.

### Set and read a policy

Set `DEPOT_TOKEN` to an organization token. These examples replace the explicit policy for `team/app` with a policy that keeps 10 images, then read it back. They print only the retention values.

Node.js SDKGo SDK

```javascript
import {createClient} from '@depot/sdk-node'

const token = process.env.DEPOT_TOKEN
if (!token) throw new Error('Set DEPOT_TOKEN to an organization token')

const registry = createClient({token}).registry.v1beta1.RegistryService

await registry.upsertRetentionPolicy({repository: 'team/app', enabled: true, keepCount: 10})

const {policy} = await registry.getRetentionPolicy({repository: 'team/app'})
console.log(policy ? {keepCount: policy.keepCount, keepDays: policy.keepDays} : 'No explicit policy')
```

For a time-based organization default, change `repository` to `**` and replace `keepCount: 10` with `keepDays: 30`. In Go, use `Repository: "**"` and `KeepDays: proto.Int32(30)`, leaving `KeepCount` unset. Go uses pointers to distinguish an absent strategy from zero.

`GetRetentionPolicy` reads the explicit policy for the requested scope. An absent `policy` in Node.js or a nil `Policy` in Go means that scope has no explicit policy; it doesn't mean an inherited policy is absent.

### Remove an explicit policy

Using the client and token above, remove the repository's explicit policy:

Node.js SDKGo SDK

```javascript
await registry.deleteRetentionPolicy({repository: 'team/app'})
```

An inherited policy may still apply after you remove a repository policy. Use `**` to remove the explicit organization-default policy. Deleting a policy doesn't delete the repository or its images, and it doesn't restore images already removed by retention.

## Registry service

Docs: [`depot.build.v1.RegistryService`](https://buf.build/depot/api/docs/main:depot.build.v1#depot.build.v1.RegistryService)

The Registry service provides access to the underlying registry that stores the images built by Depot. You can use this service to list and delete images.

### List the images for a project

To list the images for a project, you need to pass the ID of the project you want to list the images for. When listing more than 100 images, you can use the `pageSize` and `pageToken` fields to paginate the results.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.build.v1.RegistryService.listImages(
  {
    projectId: 'project-id',
    pageSize: 100,
    pageToken: undefined,
  },
  {headers},
)

console.log(result.images)
console.log(result.nextPageToken)
```

The images returned will consist of an image tag, digest, a pushedAt timestamp, and the size of the image in bytes.

### Delete images

To delete images, you need to pass the ID of the project and the list of image tags you want to remove.

Node.js SDKGo SDK

```javascript
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

await depot.build.v1.RegistryService.deleteImage(
  {
    projectId: 'project-id',
    imageTags: ['image-tag-1', 'image-tag-2'],
  },
  {headers},
)
```

## BuildKit service

Docs: [`depot.buildkit.v1.BuildKitService`](https://buf.build/depot/api/docs/main:depot.buildkit.v1#depot.buildkit.v1.BuildKitService)

The BuildKit service provides lower level access to the underlying BuildKit endpoints that power the image builds. They give you the ability to interact with the underlying builders without needing the Depot CLI as a dependency. For example, you can use the [`buildx` Go library](https://pkg.go.dev/github.com/docker/buildx) with the given BuildKit endpoint to build images from your own code via Depot.

### Get a BuildKit endpoint

To get a BuildKit endpoint, you need to pass the ID of the build you want to get the endpoint for and the platform you want to build.

Supported platforms:

- `PLATFORM_AMD64` for `linux/amd64` builds
- `PLATFORM_ARM64` for `linux/arm64` builds

**Note:** The BuildKit service requires the [buildx Go library](https://pkg.go.dev/github.com/docker/buildx). While the Node.js SDK includes these methods, you can only use buildx with Go.

```go
import (
    "github.com/depot/depot-go/build"
    "github.com/depot/depot-go/machine"
    cliv1 "github.com/depot/depot-go/proto/depot/cli/v1"
)

token := os.Getenv("DEPOT_TOKEN")
projectID := os.Getenv("DEPOT_PROJECT_ID")

// Create a build
build, err := build.NewBuild(ctx, &cliv1.CreateBuildRequest{
    ProjectId: projectID,
}, token)
if err != nil {
    log.Fatal(err)
}

// Acquire a BuildKit machine
buildkit, err := machine.Acquire(ctx, build.ID, build.Token, "amd64")
if err != nil {
    log.Fatal(err)
}

defer buildkit.Release()

// Connect to BuildKit
buildkitClient, err := buildkit.Connect(ctx)
if err != nil {
    log.Fatal(err)
}
```

When a connection is active and ready to be used, you can use the `buildkitClient` to execute builds using the BuildKit API.

### Report the health of a build

To report the health of a build, you need to pass the ID of the build you want to report and the platform.

**Once you acquire a BuildKit endpoint, you must report the health of the build to Depot or the underlying resources will be removed after 5 minutes of inactivity.**

```go
import (
    "net/http"
    buildkitv1 "buf.build/gen/go/depot/api/protocolbuffers/go/depot/buildkit/v1"
    "buf.build/gen/go/depot/api/connectrpc/go/depot/buildkit/v1/buildkitv1connect"
    "connectrpc.com/connect"
)

buildToken := os.Getenv("BUILD_TOKEN")

client := buildkitv1connect.NewBuildKitServiceClient(
    http.DefaultClient,
    "https://api.depot.dev",
)

req := connect.NewRequest(&buildkitv1.ReportHealthRequest{
    BuildId: "build-id",
    Platform: buildkitv1.Platform_PLATFORM_AMD64,
})

req.Header().Set("Authorization", fmt.Sprintf("Bearer %s", buildToken))

_, err := client.ReportHealth(ctx, req)
if err != nil {
    log.Fatal(err)
}
```

### Release the endpoint for a build

To release the endpoint for a build, you need to pass the ID of the build you want to release and the platform.

This endpoint tells Depot you're done using that endpoint and we can schedule it for removal.

```go
import (
    "github.com/depot/depot-go/machine"
)

// The buildkit.Release() method handles releasing the endpoint
defer buildkit.Release()
```

## Usage service

Docs: [`depot.core.v1.UsageService`](https://buf.build/depot/api/docs/main:depot.core.v1#depot.core.v1.UsageService)

The UsageService service enables consuming resource utilization data via API.

### List project usage

List usage for all projects over a time range. Use `nextPageToken` from a response to request the next page.

Node.js SDKGo SDK

```javascript
import {depot, wkt} from '@depot/sdk-node'
const {timestampFromDate} = wkt
const headers = {Authorization: `Bearer ${process.env.DEPOT_TOKEN}`}

const result = await depot.core.v1.UsageService.listProjectUsage(
  {
    startAt: timestampFromDate(new Date('2025-09-01T00:00:00Z')),
    endAt: timestampFromDate(new Date('2025-09-30T23:59:59Z')),
    pageSize: 100,
  },
  {headers},
)

console.log(result.usage, result.nextPageToken)
```

### Get usage for one project

To get usage for a given project, you need to pass a project id, and the starting and ending timestamp of the desired period. All three parameters are mandatory.

Node.js SDKGo SDK

```javascript
import {depot, wkt} from '@depot/sdk-node'
const {timestampFromDate} = wkt

const headers = {
  Authorization: `Bearer ${process.env.DEPOT_TOKEN}`,
}

const request = {
  projectId: 'myprojectid',
  startAt: timestampFromDate(new Date('2025-09-01T00:00:00Z')),
  endAt: timestampFromDate(new Date('2025-09-30T23:59:59Z')),
}

const result = await depot.core.v1.UsageService.getProjectUsage(request, {headers})
console.log(result.usage)
```

### Get usage for a given period

To get usage data for your organization for a specific period of time, you need to pass the starting and ending timestamp of the period. Both `startAt` and `endAt` are mandatory parameters.

`getUsage` returns the same data as the CSV generated via `Settings > Usage > Usage History`.

Node.js SDKGo SDK

```javascript
import {depot, wkt} from '@depot/sdk-node'
const {timestampFromDate} = wkt

const headers = {
  Authorization: `Bearer ${process.env.DEPOT_TOKEN}`,
}

const request = {
  startAt: timestampFromDate(new Date('2025-09-01T00:00:00Z')),
  endAt: timestampFromDate(new Date('2025-09-30T23:59:59Z')),
}

const result = await depot.core.v1.UsageService.getUsage(request, {headers})

console.log(result.containerBuild)
console.log(result.githubActionsJobs)
console.log(result.storage)
console.log(result.agentSandbox)
```
