@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
228 lines • 9.28 kB
JavaScript
import { APIResource } from "../../core/resource.mjs";
import { BadRequestError, ConflictError } from "../../core/error.mjs";
import { PageCursor } from "../../core/pagination.mjs";
import { startApiCallSpan } from "../../internal/tracing.mjs";
import { path } from "../../internal/utils/path.mjs";
/**
* The External Key can't be deleted or reconfigured while the organization's
* Workspace Policy lists it as an allowed key.
*/
export var ExternalKeyInWorkspacePolicyError = /* @__PURE__ */ (() => {
/**
* The External Key can't be deleted or reconfigured while the organization's
* Workspace Policy lists it as an allowed key.
*/
class ExternalKeyInWorkspacePolicyError extends BadRequestError {
}
/** @internal */
ExternalKeyInWorkspacePolicyError._errorName = 'ExternalKeyInWorkspacePolicyError';
return ExternalKeyInWorkspacePolicyError;
})();
/**
* The External Key failed Anthropic's validation, so the request was refused. The
* message gives the reason, if there is one.
*/
export var ExternalKeyValidationFailedError = /* @__PURE__ */ (() => {
/**
* The External Key failed Anthropic's validation, so the request was refused. The
* message gives the reason, if there is one.
*/
class ExternalKeyValidationFailedError extends BadRequestError {
}
/** @internal */
ExternalKeyValidationFailedError._errorName = 'ExternalKeyValidationFailedError';
return ExternalKeyValidationFailedError;
})();
/**
* Anthropic's validation of the External Key did not finish in time, so the
* request was refused. Wait a moment, then send the request again.
*/
export var ExternalKeyValidationTimedOutError = /* @__PURE__ */ (() => {
/**
* Anthropic's validation of the External Key did not finish in time, so the
* request was refused. Wait a moment, then send the request again.
*/
class ExternalKeyValidationTimedOutError extends BadRequestError {
}
/** @internal */
ExternalKeyValidationTimedOutError._errorName = 'ExternalKeyValidationTimedOutError';
return ExternalKeyValidationTimedOutError;
})();
/**
* The external key changed while the request was validating it. Send the request
* again.
*/
export var ExternalKeyChangedError = /* @__PURE__ */ (() => {
/**
* The external key changed while the request was validating it. Send the request
* again.
*/
class ExternalKeyChangedError extends ConflictError {
}
/** @internal */
ExternalKeyChangedError._errorName = 'ExternalKeyChangedError';
return ExternalKeyChangedError;
})();
export var ExternalKeys = /* @__PURE__ */ (() => {
class ExternalKeys extends APIResource {
/**
* Create an external key config owned by the caller's organization.
*
* @throws {UserProfileNotFoundError}
* @throws {SandboxEgressRestrictedError}
*
* @example
* ```ts
* const externalKey =
* await client.organization.externalKeys.create({
* provider_config: {
* kms_arn:
* 'arn:aws:kms:us-east-1:111122223333:key/abcd1234-5678-90ab-cdef-000011112222',
* type: 'aws',
* },
* });
* ```
*/
create(body, options) {
return this._client.post('/v1/organizations/external_keys', {
body,
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.create', options, {
route: '/v1/organizations/external_keys',
createdIDAttribute: 'anthropic.organization.external_key.id',
}),
});
}
/**
* Retrieve a single external key config in the caller's organization by ID.
*
* @example
* ```ts
* const externalKey =
* await client.organization.externalKeys.retrieve(
* 'external_key_id',
* );
* ```
*/
retrieve(externalKeyID, options) {
return this._client.get(path `/v1/organizations/external_keys/${externalKeyID}`, {
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.retrieve', options, {
route: '/v1/organizations/external_keys/{external_key_id}',
attributes: { 'anthropic.organization.external_key.id': externalKeyID },
}),
});
}
/**
* Partially update an external key config. Omitted fields are left unchanged.
*
* `display_name` is always editable. `geo` and `provider_config` cannot be changed
* once any workspace references this config, and a Google Cloud key's provider and
* `key_name` cannot be changed at all.
*
* @throws {ExternalKeyInWorkspacePolicyError}
* @throws {SandboxEgressRestrictedError}
*
* @example
* ```ts
* const externalKey =
* await client.organization.externalKeys.update(
* 'external_key_id',
* {},
* );
* ```
*/
update(externalKeyID, body, options) {
return this._client.post(path `/v1/organizations/external_keys/${externalKeyID}`, {
body,
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.update', options, {
route: '/v1/organizations/external_keys/{external_key_id}',
attributes: { 'anthropic.organization.external_key.id': externalKeyID },
}),
});
}
/**
* List external key configs in the caller's organization.
*
* Results are ordered by creation time (newest first). Use the `next_page` cursor
* from the response to fetch subsequent pages.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const externalKey of client.organization.externalKeys.list()) {
* // ...
* }
* ```
*/
list(query = {}, options) {
return this._client.getAPIList('/v1/organizations/external_keys', (PageCursor), {
query,
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.list', options, {
route: '/v1/organizations/external_keys',
queryParams: ['limit', 'page'],
}),
});
}
/**
* Delete an external key config.
*
* The request is rejected if any workspace still references this config.
*
* @throws {ExternalKeyInWorkspacePolicyError}
* @throws {SandboxEgressRestrictedError}
*
* @example
* ```ts
* const externalKey =
* await client.organization.externalKeys.delete(
* 'external_key_id',
* );
* ```
*/
delete(externalKeyID, options) {
return this._client.delete(path `/v1/organizations/external_keys/${externalKeyID}`, {
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.delete', options, {
route: '/v1/organizations/external_keys/{external_key_id}',
attributes: { 'anthropic.organization.external_key.id': externalKeyID },
}),
});
}
/**
* Validate an external key config against the customer's KMS.
*
* Anthropic performs an encrypt/decrypt roundtrip against the configured KMS key
* and waits up to 30 seconds for the result. The response status is `success` if
* the roundtrip succeeded, or `failure` with an error message if it failed or
* timed out.
*
* @throws {SandboxEgressRestrictedError}
*
* @example
* ```ts
* const response =
* await client.organization.externalKeys.validate(
* 'external_key_id',
* );
* ```
*/
validate(externalKeyID, options) {
return this._client.post(path `/v1/organizations/external_keys/${externalKeyID}/validate`, {
...options,
__span: startApiCallSpan(this._client, 'anthropic.organization.external_keys.validate', options, {
route: '/v1/organizations/external_keys/{external_key_id}/validate',
attributes: { 'anthropic.organization.external_key.id': externalKeyID },
}),
});
}
}
ExternalKeys.ExternalKeyInWorkspacePolicyError = ExternalKeyInWorkspacePolicyError;
ExternalKeys.ExternalKeyValidationFailedError = ExternalKeyValidationFailedError;
ExternalKeys.ExternalKeyValidationTimedOutError = ExternalKeyValidationTimedOutError;
ExternalKeys.ExternalKeyChangedError = ExternalKeyChangedError;
return ExternalKeys;
})();
//# sourceMappingURL=external-keys.mjs.map