@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
313 lines • 12.8 kB
JavaScript
import { APIResource } from "../../../core/resource.mjs";
import * as WorkAPI from "./work.mjs";
import { BetaHeartbeatPreconditionFailedError, Work, } from "./work.mjs";
import { BadRequestError, NotFoundError, PermissionDeniedError } from "../../../core/error.mjs";
import { PageCursor } from "../../../core/pagination.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { startApiCallSpan } from "../../../internal/tracing.mjs";
import { path } from "../../../internal/utils/path.mjs";
/**
* The environment is archived, so it cannot be updated.
*/
export var BetaEnvironmentArchivedError = /* @__PURE__ */ (() => {
/**
* The environment is archived, so it cannot be updated.
*/
class BetaEnvironmentArchivedError extends BadRequestError {
}
/** @internal */
BetaEnvironmentArchivedError._errorName = 'BetaEnvironmentArchivedError';
return BetaEnvironmentArchivedError;
})();
/**
* `config.type` differs from the environment's stored type, which cannot change
* after creation.
*/
export var BetaInvalidConfigTypeChangeError = /* @__PURE__ */ (() => {
/**
* `config.type` differs from the environment's stored type, which cannot change
* after creation.
*/
class BetaInvalidConfigTypeChangeError extends BadRequestError {
}
/** @internal */
BetaInvalidConfigTypeChangeError._errorName = 'BetaInvalidConfigTypeChangeError';
return BetaInvalidConfigTypeChangeError;
})();
/**
* `metadata` has too many keys, a key or value that is too long, or a reserved
* key. The message names each problem.
*/
export var BetaInvalidMetadataError = /* @__PURE__ */ (() => {
/**
* `metadata` has too many keys, a key or value that is too long, or a reserved
* key. The message names each problem.
*/
class BetaInvalidMetadataError extends BadRequestError {
}
/** @internal */
BetaInvalidMetadataError._errorName = 'BetaInvalidMetadataError';
return BetaInvalidMetadataError;
})();
/**
* Anthropic has turned off creating environments for this organization. Existing
* environments still work.
*/
export var BetaEnvironmentCreateDisabledError = /* @__PURE__ */ (() => {
/**
* Anthropic has turned off creating environments for this organization. Existing
* environments still work.
*/
class BetaEnvironmentCreateDisabledError extends PermissionDeniedError {
}
/** @internal */
BetaEnvironmentCreateDisabledError._errorName = 'BetaEnvironmentCreateDisabledError';
return BetaEnvironmentCreateDisabledError;
})();
/**
* Anthropic has turned off updating environments for this organization. Existing
* environments still work as they are.
*/
export var BetaEnvironmentUpdateDisabledError = /* @__PURE__ */ (() => {
/**
* Anthropic has turned off updating environments for this organization. Existing
* environments still work as they are.
*/
class BetaEnvironmentUpdateDisabledError extends PermissionDeniedError {
}
/** @internal */
BetaEnvironmentUpdateDisabledError._errorName = 'BetaEnvironmentUpdateDisabledError';
return BetaEnvironmentUpdateDisabledError;
})();
/**
* `settings.environment_id` names no Environment within the organization's reach.
*/
export var BetaEnvironmentNotFoundError = /* @__PURE__ */ (() => {
/**
* `settings.environment_id` names no Environment within the organization's reach.
*/
class BetaEnvironmentNotFoundError extends NotFoundError {
}
/** @internal */
BetaEnvironmentNotFoundError._errorName = 'BetaEnvironmentNotFoundError';
return BetaEnvironmentNotFoundError;
})();
export var Environments = /* @__PURE__ */ (() => {
class Environments extends APIResource {
constructor() {
super(...arguments);
this.work = new WorkAPI.Work(this._client);
}
/**
* Create a new environment with the specified configuration.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
* @throws {BetaEnvironmentCreateDisabledError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.create({
* name: 'python-data-analysis',
* });
* ```
*/
create(params, options) {
const { betas, workspace_id, ...body } = params;
return this._client.post('/v1/environments', {
body,
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.create', options, {
route: '/v1/environments',
createdIDAttribute: 'anthropic.environment.id',
}),
});
}
/**
* Retrieve a specific environment by ID.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.retrieve(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
retrieve(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.get(path `/v1/environments/${environmentID}`, {
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.retrieve', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* Update an existing environment's configuration.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {BetaEnvironmentArchivedError}
* @throws {BetaInvalidConfigTypeChangeError}
* @throws {OrganizationOnHoldError}
* @throws {BetaEnvironmentUpdateDisabledError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.update(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* {},
* );
* ```
*/
update(environmentID, params, options) {
const { betas, workspace_id, ...body } = params;
return this._client.post(path `/v1/environments/${environmentID}`, {
body,
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.update', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* List environments with pagination support.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaEnvironment of client.beta.environments.list()) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { betas, workspace_id, ...query } = params ?? {};
return this._client.getAPIList('/v1/environments', (PageCursor), {
query,
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.list', options, {
route: '/v1/environments',
queryParams: ['include_archived', 'limit', 'page'],
}),
});
}
/**
* Delete an environment by ID. Returns a confirmation of the deletion.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironmentDeleteResponse =
* await client.beta.environments.delete(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
delete(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.delete(path `/v1/environments/${environmentID}`, {
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.delete', options, {
route: '/v1/environments/{environment_id}',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
/**
* Archive an environment by ID. Archived environments cannot be used to create new
* sessions.
*
* @throws {ClaudeCodeKeyCreatorNotMemberError}
* @throws {OrganizationOnHoldError}
*
* @example
* ```ts
* const betaEnvironment =
* await client.beta.environments.archive(
* 'env_011CZkZ9X2dpNyB7HsEFoRfW',
* );
* ```
*/
archive(environmentID, params = {}, options) {
const { betas, workspace_id } = params ?? {};
return this._client.post(path `/v1/environments/${environmentID}/archive`, {
...options,
headers: buildHeaders([
{
'anthropic-beta': [...(betas ?? []), 'managed-agents-2026-04-01'].toString(),
...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined),
},
options?.headers,
]),
__qualifiers: { beta: 'true' },
__span: startApiCallSpan(this._client, 'anthropic.environments.archive', options, {
route: '/v1/environments/{environment_id}/archive',
attributes: { 'anthropic.environment.id': environmentID },
}),
});
}
}
Environments.BetaEnvironmentArchivedError = BetaEnvironmentArchivedError;
Environments.BetaInvalidConfigTypeChangeError = BetaInvalidConfigTypeChangeError;
Environments.BetaInvalidMetadataError = BetaInvalidMetadataError;
Environments.BetaEnvironmentCreateDisabledError = BetaEnvironmentCreateDisabledError;
Environments.BetaEnvironmentUpdateDisabledError = BetaEnvironmentUpdateDisabledError;
Environments.BetaEnvironmentNotFoundError = BetaEnvironmentNotFoundError;
Environments.Work = Work;
Environments.BetaHeartbeatPreconditionFailedError = BetaHeartbeatPreconditionFailedError;
return Environments;
})();
//# sourceMappingURL=environments.mjs.map