Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@anthropic-ai/sdk

Package Overview
Dependencies
Maintainers
9
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anthropic-ai/sdk - npm Package Compare versions

Comparing version 0.32.1 to 0.33.0

resources/beta/models.d.ts

20

core.d.ts

@@ -16,2 +16,5 @@

};
type WithRequestID<T> = T extends Array<any> | Response | AbstractPage<any> ? T : T extends Record<string, any> ? T & {
_request_id?: string | null;
} : T;
/**

@@ -21,7 +24,7 @@ * A subclass of `Promise` providing additional helper methods

*/
export declare class APIPromise<T> extends Promise<T> {
export declare class APIPromise<T> extends Promise<WithRequestID<T>> {
private responsePromise;
private parseResponse;
private parsedPromise;
constructor(responsePromise: Promise<APIResponseProps>, parseResponse?: (props: APIResponseProps) => PromiseOrValue<T>);
constructor(responsePromise: Promise<APIResponseProps>, parseResponse?: (props: APIResponseProps) => PromiseOrValue<WithRequestID<T>>);
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U>;

@@ -43,3 +46,5 @@ /**

/**
* Gets the parsed response data and the raw `Response` instance.
* Gets the parsed response data, the raw `Response` instance and the ID of the request,
* returned vie the `request-id` header which is useful for debugging requests and resporting
* issues to Anthropic.
*

@@ -49,3 +54,2 @@ * If you just want to get the raw `Response` instance without parsing it,

*
*
* 👋 Getting the wrong TypeScript type for `Response`?

@@ -60,7 +64,8 @@ * Try setting `"moduleResolution": "NodeNext"` if you can,

response: Response;
request_id: string | null | undefined;
}>;
private parse;
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult>;
finally(onfinally?: (() => void) | undefined | null): Promise<T>;
then<TResult1 = WithRequestID<T>, TResult2 = never>(onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<WithRequestID<T> | TResult>;
finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>>;
}

@@ -136,3 +141,2 @@ export declare abstract class APIClient {

fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise<Response>;
protected getRequestClient(): RequestClient;
private shouldRetry;

@@ -139,0 +143,0 @@ private retryRequest;

34

core.js

@@ -48,3 +48,3 @@ "use strict";

debug('response', response.status, response.url, response.headers, json);
return json;
return _addRequestID(json, response);
}

@@ -56,2 +56,11 @@ const text = await response.text();

}
function _addRequestID(value, response) {
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return value;
}
return Object.defineProperty(value, '_request_id', {
value: response.headers.get('request-id'),
enumerable: false,
});
}
/**

@@ -73,3 +82,3 @@ * A subclass of `Promise` providing additional helper methods

_thenUnwrap(transform) {
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props), props));
return new APIPromise(this.responsePromise, async (props) => _addRequestID(transform(await this.parseResponse(props), props), props.response));
}

@@ -93,3 +102,5 @@ /**

/**
* Gets the parsed response data and the raw `Response` instance.
* Gets the parsed response data, the raw `Response` instance and the ID of the request,
* returned vie the `request-id` header which is useful for debugging requests and resporting
* issues to Anthropic.
*

@@ -99,3 +110,2 @@ * If you just want to get the raw `Response` instance without parsing it,

*
*
* 👋 Getting the wrong TypeScript type for `Response`?

@@ -109,3 +119,3 @@ * Try setting `"moduleResolution": "NodeNext"` if you can,

const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
return { data, response };
return { data, response, request_id: response.headers.get('request-id') };
}

@@ -373,12 +383,8 @@ parse() {

const timeout = setTimeout(() => controller.abort(), ms);
return (this.getRequestClient()
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
.fetch.call(undefined, url, { signal: controller.signal, ...options })
.finally(() => {
return (
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
this.fetch.call(undefined, url, { signal: controller.signal, ...options }).finally(() => {
clearTimeout(timeout);
}));
}
getRequestClient() {
return { fetch: this.fetch };
}
shouldRetry(response) {

@@ -705,4 +711,4 @@ // Note this is not a standard header.

exports.safeJSON = safeJSON;
// https://stackoverflow.com/a/19709846
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url) => {

@@ -709,0 +715,0 @@ return startsWithSchemeRegexp.test(url);

import { Headers } from "./core.js";
export declare class AnthropicError extends Error {
}
export declare class APIError extends AnthropicError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;
export declare class APIError<TStatus extends number | undefined = number | undefined, THeaders extends Headers | undefined = Headers | undefined, TError extends Object | undefined = Object | undefined> extends AnthropicError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
readonly headers: THeaders;
/** JSON body of the response that caused the error */
readonly error: TError;
readonly request_id: string | null | undefined;
constructor(status: number | undefined, error: Object | undefined, message: string | undefined, headers: Headers | undefined);
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders);
private static makeMessage;
static generate(status: number | undefined, errorResponse: Object | undefined, message: string | undefined, headers: Headers | undefined): APIError;
}
export declare class APIUserAbortError extends APIError {
readonly status: undefined;
export declare class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }?: {

@@ -19,4 +21,3 @@ message?: string;

}
export declare class APIConnectionError extends APIError {
readonly status: undefined;
export declare class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: {

@@ -32,25 +33,18 @@ message?: string | undefined;

}
export declare class BadRequestError extends APIError {
readonly status: 400;
export declare class BadRequestError extends APIError<400, Headers> {
}
export declare class AuthenticationError extends APIError {
readonly status: 401;
export declare class AuthenticationError extends APIError<401, Headers> {
}
export declare class PermissionDeniedError extends APIError {
readonly status: 403;
export declare class PermissionDeniedError extends APIError<403, Headers> {
}
export declare class NotFoundError extends APIError {
readonly status: 404;
export declare class NotFoundError extends APIError<404, Headers> {
}
export declare class ConflictError extends APIError {
readonly status: 409;
export declare class ConflictError extends APIError<409, Headers> {
}
export declare class UnprocessableEntityError extends APIError {
readonly status: 422;
export declare class UnprocessableEntityError extends APIError<422, Headers> {
}
export declare class RateLimitError extends APIError {
readonly status: 429;
export declare class RateLimitError extends APIError<429, Headers> {
}
export declare class InternalServerError extends APIError {
export declare class InternalServerError extends APIError<number, Headers> {
}
//# sourceMappingURL=error.d.ts.map

@@ -36,3 +36,3 @@ "use strict";

static generate(status, errorResponse, message, headers) {
if (!status) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: (0, core_1.castToError)(errorResponse) });

@@ -72,3 +72,2 @@ }

super(undefined, undefined, message || 'Request was aborted.', undefined);
this.status = undefined;
}

@@ -80,3 +79,2 @@ }

super(undefined, undefined, message || 'Connection error.', undefined);
this.status = undefined;
// in some environments the 'cause' property is already declared

@@ -96,48 +94,20 @@ // @ts-ignore

class BadRequestError extends APIError {
constructor() {
super(...arguments);
this.status = 400;
}
}
exports.BadRequestError = BadRequestError;
class AuthenticationError extends APIError {
constructor() {
super(...arguments);
this.status = 401;
}
}
exports.AuthenticationError = AuthenticationError;
class PermissionDeniedError extends APIError {
constructor() {
super(...arguments);
this.status = 403;
}
}
exports.PermissionDeniedError = PermissionDeniedError;
class NotFoundError extends APIError {
constructor() {
super(...arguments);
this.status = 404;
}
}
exports.NotFoundError = NotFoundError;
class ConflictError extends APIError {
constructor() {
super(...arguments);
this.status = 409;
}
}
exports.ConflictError = ConflictError;
class UnprocessableEntityError extends APIError {
constructor() {
super(...arguments);
this.status = 422;
}
}
exports.UnprocessableEntityError = UnprocessableEntityError;
class RateLimitError extends APIError {
constructor() {
super(...arguments);
this.status = 429;
}
}

@@ -144,0 +114,0 @@ exports.RateLimitError = RateLimitError;

@@ -9,4 +9,5 @@ import { type Agent } from "./_shims/index.js";

import { Completion, CompletionCreateParams, CompletionCreateParamsNonStreaming, CompletionCreateParamsStreaming, Completions } from "./resources/completions.js";
import { ContentBlock, ContentBlockDeltaEvent, ContentBlockStartEvent, ContentBlockStopEvent, ImageBlockParam, InputJSONDelta, Message, MessageCreateParams, MessageCreateParamsNonStreaming, MessageCreateParamsStreaming, MessageDeltaEvent, MessageDeltaUsage, MessageParam, MessageStartEvent, MessageStopEvent, MessageStreamEvent, MessageStreamParams, Messages, Metadata, Model, RawContentBlockDeltaEvent, RawContentBlockStartEvent, RawContentBlockStopEvent, RawMessageDeltaEvent, RawMessageStartEvent, RawMessageStopEvent, RawMessageStreamEvent, TextBlock, TextBlockParam, TextDelta, Tool, ToolChoice, ToolChoiceAny, ToolChoiceAuto, ToolChoiceTool, ToolResultBlockParam, ToolUseBlock, ToolUseBlockParam, Usage } from "./resources/messages.js";
import { AnthropicBeta, Beta, BetaAPIError, BetaAuthenticationError, BetaError, BetaErrorResponse, BetaInvalidRequestError, BetaNotFoundError, BetaOverloadedError, BetaPermissionError, BetaRateLimitError } from "./resources/beta/beta.js";
import { ModelInfo, ModelInfosPage, ModelListParams, Models } from "./resources/models.js";
import { AnthropicBeta, Beta, BetaAPIError, BetaAuthenticationError, BetaBillingError, BetaError, BetaErrorResponse, BetaGatewayTimeoutError, BetaInvalidRequestError, BetaNotFoundError, BetaOverloadedError, BetaPermissionError, BetaRateLimitError } from "./resources/beta/beta.js";
import { Base64PDFSource, CacheControlEphemeral, ContentBlock, ContentBlockDeltaEvent, ContentBlockParam, ContentBlockStartEvent, ContentBlockStopEvent, DocumentBlockParam, ImageBlockParam, InputJSONDelta, Message, MessageCountTokensParams, MessageCreateParams, MessageCreateParamsNonStreaming, MessageCreateParamsStreaming, MessageDeltaEvent, MessageDeltaUsage, MessageParam, MessageStartEvent, MessageStopEvent, MessageStreamEvent, MessageStreamParams, MessageTokensCount, Messages, Metadata, Model, RawContentBlockDeltaEvent, RawContentBlockStartEvent, RawContentBlockStopEvent, RawMessageDeltaEvent, RawMessageStartEvent, RawMessageStopEvent, RawMessageStreamEvent, TextBlock, TextBlockParam, TextDelta, Tool, ToolChoice, ToolChoiceAny, ToolChoiceAuto, ToolChoiceTool, ToolResultBlockParam, ToolUseBlock, ToolUseBlockParam, Usage } from "./resources/messages/messages.js";
export interface ClientOptions {

@@ -100,2 +101,3 @@ /**

messages: API.Messages;
models: API.Models;
beta: API.Beta;

@@ -128,6 +130,2 @@ protected defaultQuery(): Core.DefaultQuery | undefined;

}
export declare const HUMAN_PROMPT: string, AI_PROMPT: string;
export { AnthropicError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./error.js";
export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;
export declare namespace Anthropic {

@@ -138,6 +136,21 @@ export type RequestOptions = Core.RequestOptions;

export { Completions as Completions, type Completion as Completion, type CompletionCreateParams as CompletionCreateParams, type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming, type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming, };
export { Messages as Messages, type ContentBlock as ContentBlock, type ContentBlockDeltaEvent as ContentBlockDeltaEvent, type ContentBlockStartEvent as ContentBlockStartEvent, type ContentBlockStopEvent as ContentBlockStopEvent, type ImageBlockParam as ImageBlockParam, type InputJSONDelta as InputJSONDelta, type Message as Message, type MessageDeltaEvent as MessageDeltaEvent, type MessageDeltaUsage as MessageDeltaUsage, type MessageParam as MessageParam, type MessageStartEvent as MessageStartEvent, type MessageStopEvent as MessageStopEvent, type MessageStreamEvent as MessageStreamEvent, type Metadata as Metadata, type Model as Model, type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent, type RawContentBlockStartEvent as RawContentBlockStartEvent, type RawContentBlockStopEvent as RawContentBlockStopEvent, type RawMessageDeltaEvent as RawMessageDeltaEvent, type RawMessageStartEvent as RawMessageStartEvent, type RawMessageStopEvent as RawMessageStopEvent, type RawMessageStreamEvent as RawMessageStreamEvent, type TextBlock as TextBlock, type TextBlockParam as TextBlockParam, type TextDelta as TextDelta, type Tool as Tool, type ToolChoice as ToolChoice, type ToolChoiceAny as ToolChoiceAny, type ToolChoiceAuto as ToolChoiceAuto, type ToolChoiceTool as ToolChoiceTool, type ToolResultBlockParam as ToolResultBlockParam, type ToolUseBlock as ToolUseBlock, type ToolUseBlockParam as ToolUseBlockParam, type Usage as Usage, type MessageCreateParams as MessageCreateParams, type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming as MessageCreateParamsStreaming, type MessageStreamParams as MessageStreamParams, };
export { Beta as Beta, type AnthropicBeta as AnthropicBeta, type BetaAPIError as BetaAPIError, type BetaAuthenticationError as BetaAuthenticationError, type BetaError as BetaError, type BetaErrorResponse as BetaErrorResponse, type BetaInvalidRequestError as BetaInvalidRequestError, type BetaNotFoundError as BetaNotFoundError, type BetaOverloadedError as BetaOverloadedError, type BetaPermissionError as BetaPermissionError, type BetaRateLimitError as BetaRateLimitError, };
export { Messages as Messages, type Base64PDFSource as Base64PDFSource, type CacheControlEphemeral as CacheControlEphemeral, type ContentBlock as ContentBlock, type ContentBlockDeltaEvent as ContentBlockDeltaEvent, type ContentBlockParam as ContentBlockParam, type ContentBlockStartEvent as ContentBlockStartEvent, type ContentBlockStopEvent as ContentBlockStopEvent, type DocumentBlockParam as DocumentBlockParam, type ImageBlockParam as ImageBlockParam, type InputJSONDelta as InputJSONDelta, type Message as Message, type MessageDeltaEvent as MessageDeltaEvent, type MessageDeltaUsage as MessageDeltaUsage, type MessageParam as MessageParam, type MessageStartEvent as MessageStartEvent, type MessageStopEvent as MessageStopEvent, type MessageStreamEvent as MessageStreamEvent, type MessageTokensCount as MessageTokensCount, type Metadata as Metadata, type Model as Model, type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent, type RawContentBlockStartEvent as RawContentBlockStartEvent, type RawContentBlockStopEvent as RawContentBlockStopEvent, type RawMessageDeltaEvent as RawMessageDeltaEvent, type RawMessageStartEvent as RawMessageStartEvent, type RawMessageStopEvent as RawMessageStopEvent, type RawMessageStreamEvent as RawMessageStreamEvent, type TextBlock as TextBlock, type TextBlockParam as TextBlockParam, type TextDelta as TextDelta, type Tool as Tool, type ToolChoice as ToolChoice, type ToolChoiceAny as ToolChoiceAny, type ToolChoiceAuto as ToolChoiceAuto, type ToolChoiceTool as ToolChoiceTool, type ToolResultBlockParam as ToolResultBlockParam, type ToolUseBlock as ToolUseBlock, type ToolUseBlockParam as ToolUseBlockParam, type Usage as Usage, type MessageCreateParams as MessageCreateParams, type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming as MessageCreateParamsStreaming, type MessageStreamParams as MessageStreamParams, type MessageCountTokensParams as MessageCountTokensParams, };
export { Models as Models, type ModelInfo as ModelInfo, ModelInfosPage as ModelInfosPage, type ModelListParams as ModelListParams, };
export { Beta as Beta, type AnthropicBeta as AnthropicBeta, type BetaAPIError as BetaAPIError, type BetaAuthenticationError as BetaAuthenticationError, type BetaBillingError as BetaBillingError, type BetaError as BetaError, type BetaErrorResponse as BetaErrorResponse, type BetaGatewayTimeoutError as BetaGatewayTimeoutError, type BetaInvalidRequestError as BetaInvalidRequestError, type BetaNotFoundError as BetaNotFoundError, type BetaOverloadedError as BetaOverloadedError, type BetaPermissionError as BetaPermissionError, type BetaRateLimitError as BetaRateLimitError, };
export type APIErrorObject = API.APIErrorObject;
export type AuthenticationError = API.AuthenticationError;
export type BillingError = API.BillingError;
export type ErrorObject = API.ErrorObject;
export type ErrorResponse = API.ErrorResponse;
export type GatewayTimeoutError = API.GatewayTimeoutError;
export type InvalidRequestError = API.InvalidRequestError;
export type NotFoundError = API.NotFoundError;
export type OverloadedError = API.OverloadedError;
export type PermissionError = API.PermissionError;
export type RateLimitError = API.RateLimitError;
}
export declare const HUMAN_PROMPT: string, AI_PROMPT: string;
export { toFile, fileFromPath } from "./uploads.js";
export { AnthropicError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./error.js";
export default Anthropic;
//# sourceMappingURL=index.d.ts.map

@@ -28,3 +28,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fileFromPath = exports.toFile = exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.AnthropicError = exports.AI_PROMPT = exports.HUMAN_PROMPT = exports.Anthropic = void 0;
exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.AnthropicError = exports.fileFromPath = exports.toFile = exports.AI_PROMPT = exports.HUMAN_PROMPT = exports.Anthropic = void 0;
const Core = __importStar(require("./core.js"));

@@ -36,4 +36,5 @@ const Errors = __importStar(require("./error.js"));

const completions_1 = require("./resources/completions.js");
const messages_1 = require("./resources/messages.js");
const models_1 = require("./resources/models.js");
const beta_1 = require("./resources/beta/beta.js");
const messages_1 = require("./resources/messages/messages.js");
/**

@@ -65,3 +66,3 @@ * API Client for interfacing with the Anthropic API.

if (!options.dangerouslyAllowBrowser && Core.isRunningInBrowser()) {
throw new Errors.AnthropicError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n\nTODO: link!\n");
throw new Errors.AnthropicError("It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n");
}

@@ -77,2 +78,3 @@ super({

this.messages = new API.Messages(this);
this.models = new API.Models(this);
this.beta = new API.Beta(this);

@@ -156,3 +158,11 @@ this._options = options;

Anthropic.fileFromPath = Uploads.fileFromPath;
Anthropic.Completions = completions_1.Completions;
Anthropic.Messages = messages_1.Messages;
Anthropic.Models = models_1.Models;
Anthropic.ModelInfosPage = models_1.ModelInfosPage;
Anthropic.Beta = beta_1.Beta;
exports.HUMAN_PROMPT = Anthropic.HUMAN_PROMPT, exports.AI_PROMPT = Anthropic.AI_PROMPT;
var uploads_1 = require("./uploads.js");
Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return uploads_1.toFile; } });
Object.defineProperty(exports, "fileFromPath", { enumerable: true, get: function () { return uploads_1.fileFromPath; } });
var error_1 = require("./error.js");

@@ -172,9 +182,4 @@ Object.defineProperty(exports, "AnthropicError", { enumerable: true, get: function () { return error_1.AnthropicError; } });

Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
exports.toFile = Uploads.toFile;
exports.fileFromPath = Uploads.fileFromPath;
Anthropic.Completions = completions_1.Completions;
Anthropic.Messages = messages_1.Messages;
Anthropic.Beta = beta_1.Beta;
exports = module.exports = Anthropic;
exports.default = Anthropic;
//# sourceMappingURL=index.js.map
{
"name": "@anthropic-ai/sdk",
"version": "0.32.1",
"version": "0.33.0",
"description": "The official TypeScript library for the Anthropic API",

@@ -5,0 +5,0 @@ "author": "Anthropic <support@anthropic.com>",

@@ -31,3 +31,3 @@ # Anthropic TypeScript API Library

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
});

@@ -53,3 +53,3 @@

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
stream: true,

@@ -81,3 +81,3 @@ });

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
};

@@ -114,3 +114,3 @@ const message: Anthropic.Message = await client.messages.create(params);

.stream({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,

@@ -153,3 +153,3 @@ messages: [

params: {
model: 'claude-3-5-sonnet-20240620',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,

@@ -162,3 +162,3 @@ messages: [{ role: 'user', content: 'Hello, world' }],

params: {
model: 'claude-3-5-sonnet-20240620',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,

@@ -207,3 +207,3 @@ messages: [{ role: 'user', content: 'Hi again, friend' }],

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})

@@ -237,2 +237,14 @@ .catch(async (err) => {

## Request IDs
> For more information on debugging requests, see [these docs](https://docs.anthropic.com/en/api/errors#request-id)
All object responses in the SDK provide a `_request_id` property which is added from the `request-id` response header so that you can quickly log failing requests and report them back to Anthropic.
```ts
const message = await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' });
console.log(completion._request_id) // req_018EeWyXxfu5pfWkrYcMdjWG
```
### Retries

@@ -254,3 +266,3 @@

// Or, configure per-request:
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-opus-20240229' }, {
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' }, {
maxRetries: 5,

@@ -272,3 +284,3 @@ });

// Override per-request:
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-opus-20240229' }, {
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' }, {
timeout: 5 * 1000,

@@ -308,3 +320,3 @@ });

while (page.hasNextPage()) {
page = page.getNextPage();
page = await page.getNextPage();
// ...

@@ -331,3 +343,3 @@ }

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
},

@@ -354,3 +366,3 @@ { headers: { 'anthropic-version': 'My-Custom-Value' } },

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})

@@ -365,3 +377,3 @@ .asResponse();

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})

@@ -478,3 +490,3 @@ .withResponse();

messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
},

@@ -506,3 +518,3 @@ {

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import Anthropic from "npm:@anthropic-ai/sdk"`.
- Deno v1.28.0 or higher.
- Bun 1.0 or later.

@@ -509,0 +521,0 @@ - Cloudflare Workers.

import { APIResource } from "../../resource.js";
import * as ModelsAPI from "./models.js";
import { BetaModelInfo, BetaModelInfosPage, ModelListParams, Models } from "./models.js";
import * as MessagesAPI from "./messages/messages.js";
import { BetaBase64PDFBlock, BetaBase64PDFSource, BetaCacheControlEphemeral, BetaContentBlock, BetaContentBlockParam, BetaImageBlockParam, BetaInputJSONDelta, BetaMessage, BetaMessageDeltaUsage, BetaMessageParam, BetaMessageTokensCount, BetaMetadata, BetaRawContentBlockDeltaEvent, BetaRawContentBlockStartEvent, BetaRawContentBlockStopEvent, BetaRawMessageDeltaEvent, BetaRawMessageStartEvent, BetaRawMessageStopEvent, BetaRawMessageStreamEvent, BetaTextBlock, BetaTextBlockParam, BetaTextDelta, BetaTool, BetaToolBash20241022, BetaToolChoice, BetaToolChoiceAny, BetaToolChoiceAuto, BetaToolChoiceTool, BetaToolComputerUse20241022, BetaToolResultBlockParam, BetaToolTextEditor20241022, BetaToolUnion, BetaToolUseBlock, BetaToolUseBlockParam, BetaUsage, MessageCountTokensParams, MessageCreateParams, MessageCreateParamsNonStreaming, MessageCreateParamsStreaming, Messages } from "./messages/messages.js";
import * as PromptCachingAPI from "./prompt-caching/prompt-caching.js";
import { PromptCaching } from "./prompt-caching/prompt-caching.js";
export declare class Beta extends APIResource {
models: ModelsAPI.Models;
messages: MessagesAPI.Messages;
promptCaching: PromptCachingAPI.PromptCaching;
}

@@ -19,3 +19,7 @@ export type AnthropicBeta = (string & {}) | 'message-batches-2024-09-24' | 'prompt-caching-2024-07-31' | 'computer-use-2024-10-22' | 'pdfs-2024-09-25' | 'token-counting-2024-11-01';

}
export type BetaError = BetaInvalidRequestError | BetaAuthenticationError | BetaPermissionError | BetaNotFoundError | BetaRateLimitError | BetaAPIError | BetaOverloadedError;
export interface BetaBillingError {
message: string;
type: 'billing_error';
}
export type BetaError = BetaInvalidRequestError | BetaAuthenticationError | BetaBillingError | BetaPermissionError | BetaNotFoundError | BetaRateLimitError | BetaGatewayTimeoutError | BetaAPIError | BetaOverloadedError;
export interface BetaErrorResponse {

@@ -25,2 +29,6 @@ error: BetaError;

}
export interface BetaGatewayTimeoutError {
message: string;
type: 'timeout_error';
}
export interface BetaInvalidRequestError {

@@ -47,6 +55,6 @@ message: string;

export declare namespace Beta {
export { type AnthropicBeta as AnthropicBeta, type BetaAPIError as BetaAPIError, type BetaAuthenticationError as BetaAuthenticationError, type BetaError as BetaError, type BetaErrorResponse as BetaErrorResponse, type BetaInvalidRequestError as BetaInvalidRequestError, type BetaNotFoundError as BetaNotFoundError, type BetaOverloadedError as BetaOverloadedError, type BetaPermissionError as BetaPermissionError, type BetaRateLimitError as BetaRateLimitError, };
export { type AnthropicBeta as AnthropicBeta, type BetaAPIError as BetaAPIError, type BetaAuthenticationError as BetaAuthenticationError, type BetaBillingError as BetaBillingError, type BetaError as BetaError, type BetaErrorResponse as BetaErrorResponse, type BetaGatewayTimeoutError as BetaGatewayTimeoutError, type BetaInvalidRequestError as BetaInvalidRequestError, type BetaNotFoundError as BetaNotFoundError, type BetaOverloadedError as BetaOverloadedError, type BetaPermissionError as BetaPermissionError, type BetaRateLimitError as BetaRateLimitError, };
export { Models as Models, type BetaModelInfo as BetaModelInfo, BetaModelInfosPage as BetaModelInfosPage, type ModelListParams as ModelListParams, };
export { Messages as Messages, type BetaBase64PDFBlock as BetaBase64PDFBlock, type BetaBase64PDFSource as BetaBase64PDFSource, type BetaCacheControlEphemeral as BetaCacheControlEphemeral, type BetaContentBlock as BetaContentBlock, type BetaContentBlockParam as BetaContentBlockParam, type BetaImageBlockParam as BetaImageBlockParam, type BetaInputJSONDelta as BetaInputJSONDelta, type BetaMessage as BetaMessage, type BetaMessageDeltaUsage as BetaMessageDeltaUsage, type BetaMessageParam as BetaMessageParam, type BetaMessageTokensCount as BetaMessageTokensCount, type BetaMetadata as BetaMetadata, type BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent, type BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent, type BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent, type BetaRawMessageDeltaEvent as BetaRawMessageDeltaEvent, type BetaRawMessageStartEvent as BetaRawMessageStartEvent, type BetaRawMessageStopEvent as BetaRawMessageStopEvent, type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent, type BetaTextBlock as BetaTextBlock, type BetaTextBlockParam as BetaTextBlockParam, type BetaTextDelta as BetaTextDelta, type BetaTool as BetaTool, type BetaToolBash20241022 as BetaToolBash20241022, type BetaToolChoice as BetaToolChoice, type BetaToolChoiceAny as BetaToolChoiceAny, type BetaToolChoiceAuto as BetaToolChoiceAuto, type BetaToolChoiceTool as BetaToolChoiceTool, type BetaToolComputerUse20241022 as BetaToolComputerUse20241022, type BetaToolResultBlockParam as BetaToolResultBlockParam, type BetaToolTextEditor20241022 as BetaToolTextEditor20241022, type BetaToolUnion as BetaToolUnion, type BetaToolUseBlock as BetaToolUseBlock, type BetaToolUseBlockParam as BetaToolUseBlockParam, type BetaUsage as BetaUsage, type MessageCreateParams as MessageCreateParams, type MessageCreateParamsNonStreaming as MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming as MessageCreateParamsStreaming, type MessageCountTokensParams as MessageCountTokensParams, };
export { PromptCaching as PromptCaching };
}
//# sourceMappingURL=beta.d.ts.map

@@ -29,16 +29,17 @@ "use strict";

const resource_1 = require("../../resource.js");
const ModelsAPI = __importStar(require("./models.js"));
const models_1 = require("./models.js");
const MessagesAPI = __importStar(require("./messages/messages.js"));
const messages_1 = require("./messages/messages.js");
const PromptCachingAPI = __importStar(require("./prompt-caching/prompt-caching.js"));
const prompt_caching_1 = require("./prompt-caching/prompt-caching.js");
class Beta extends resource_1.APIResource {
constructor() {
super(...arguments);
this.models = new ModelsAPI.Models(this._client);
this.messages = new MessagesAPI.Messages(this._client);
this.promptCaching = new PromptCachingAPI.PromptCaching(this._client);
}
}
exports.Beta = Beta;
Beta.Models = models_1.Models;
Beta.BetaModelInfosPage = models_1.BetaModelInfosPage;
Beta.Messages = messages_1.Messages;
Beta.PromptCaching = prompt_caching_1.PromptCaching;
//# sourceMappingURL=beta.js.map

@@ -1,4 +0,4 @@

export { Beta, type AnthropicBeta, type BetaAPIError, type BetaAuthenticationError, type BetaError, type BetaErrorResponse, type BetaInvalidRequestError, type BetaNotFoundError, type BetaOverloadedError, type BetaPermissionError, type BetaRateLimitError, } from "./beta.js";
export { Beta, type AnthropicBeta, type BetaAPIError, type BetaAuthenticationError, type BetaBillingError, type BetaError, type BetaErrorResponse, type BetaGatewayTimeoutError, type BetaInvalidRequestError, type BetaNotFoundError, type BetaOverloadedError, type BetaPermissionError, type BetaRateLimitError, } from "./beta.js";
export { BetaModelInfosPage, Models, type BetaModelInfo, type ModelListParams } from "./models.js";
export { Messages, type BetaBase64PDFBlock, type BetaBase64PDFSource, type BetaCacheControlEphemeral, type BetaContentBlock, type BetaContentBlockParam, type BetaImageBlockParam, type BetaInputJSONDelta, type BetaMessage, type BetaMessageDeltaUsage, type BetaMessageParam, type BetaMessageTokensCount, type BetaMetadata, type BetaRawContentBlockDeltaEvent, type BetaRawContentBlockStartEvent, type BetaRawContentBlockStopEvent, type BetaRawMessageDeltaEvent, type BetaRawMessageStartEvent, type BetaRawMessageStopEvent, type BetaRawMessageStreamEvent, type BetaTextBlock, type BetaTextBlockParam, type BetaTextDelta, type BetaTool, type BetaToolBash20241022, type BetaToolChoice, type BetaToolChoiceAny, type BetaToolChoiceAuto, type BetaToolChoiceTool, type BetaToolComputerUse20241022, type BetaToolResultBlockParam, type BetaToolTextEditor20241022, type BetaToolUnion, type BetaToolUseBlock, type BetaToolUseBlockParam, type BetaUsage, type MessageCreateParams, type MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming, type MessageCountTokensParams, } from "./messages/index.js";
export { PromptCaching } from "./prompt-caching/index.js";
//# sourceMappingURL=index.d.ts.map
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptCaching = exports.Messages = exports.Beta = void 0;
exports.Messages = exports.Models = exports.BetaModelInfosPage = exports.Beta = void 0;
var beta_1 = require("./beta.js");
Object.defineProperty(exports, "Beta", { enumerable: true, get: function () { return beta_1.Beta; } });
var models_1 = require("./models.js");
Object.defineProperty(exports, "BetaModelInfosPage", { enumerable: true, get: function () { return models_1.BetaModelInfosPage; } });
Object.defineProperty(exports, "Models", { enumerable: true, get: function () { return models_1.Models; } });
var index_1 = require("./messages/index.js");
Object.defineProperty(exports, "Messages", { enumerable: true, get: function () { return index_1.Messages; } });
var index_2 = require("./prompt-caching/index.js");
Object.defineProperty(exports, "PromptCaching", { enumerable: true, get: function () { return index_2.PromptCaching; } });
//# sourceMappingURL=index.js.map

@@ -5,4 +5,4 @@ import { APIResource } from "../../../resource.js";

import * as MessagesMessagesAPI from "./messages.js";
import * as MessagesAPI from "../../messages.js";
import * as BetaAPI from "../beta.js";
import * as MessagesAPI from "../../messages/messages.js";
import * as BatchesAPI from "./batches.js";

@@ -9,0 +9,0 @@ import { BatchCancelParams, BatchCreateParams, BatchListParams, BatchResultsParams, BatchRetrieveParams, Batches, BetaMessageBatch, BetaMessageBatchCanceledResult, BetaMessageBatchErroredResult, BetaMessageBatchExpiredResult, BetaMessageBatchIndividualResponse, BetaMessageBatchRequestCounts, BetaMessageBatchResult, BetaMessageBatchSucceededResult, BetaMessageBatchesPage } from "./batches.js";

@@ -5,3 +5,3 @@ import { APIResource } from "../resource.js";

import * as CompletionsAPI from "./completions.js";
import * as MessagesAPI from "./messages.js";
import * as MessagesAPI from "./messages/messages.js";
import { Stream } from "../streaming.js";

@@ -8,0 +8,0 @@ export declare class Completions extends APIResource {

@@ -1,4 +0,6 @@

export { Beta, type AnthropicBeta, type BetaAPIError, type BetaAuthenticationError, type BetaError, type BetaErrorResponse, type BetaInvalidRequestError, type BetaNotFoundError, type BetaOverloadedError, type BetaPermissionError, type BetaRateLimitError, } from "./beta/beta.js";
export * from "./shared.js";
export { Beta, type AnthropicBeta, type BetaAPIError, type BetaAuthenticationError, type BetaBillingError, type BetaError, type BetaErrorResponse, type BetaGatewayTimeoutError, type BetaInvalidRequestError, type BetaNotFoundError, type BetaOverloadedError, type BetaPermissionError, type BetaRateLimitError, } from "./beta/beta.js";
export { Completions, type Completion, type CompletionCreateParams, type CompletionCreateParamsNonStreaming, type CompletionCreateParamsStreaming, } from "./completions.js";
export { Messages, type ContentBlock, type ContentBlockDeltaEvent, type ContentBlockStartEvent, type ContentBlockStopEvent, type ImageBlockParam, type InputJsonDelta, type InputJSONDelta, type Message, type MessageDeltaEvent, type MessageDeltaUsage, type MessageParam, type MessageStartEvent, type MessageStopEvent, type MessageStreamEvent, type MessageStreamParams, type Metadata, type Model, type RawContentBlockDeltaEvent, type RawContentBlockStartEvent, type RawContentBlockStopEvent, type RawMessageDeltaEvent, type RawMessageStartEvent, type RawMessageStopEvent, type RawMessageStreamEvent, type TextBlock, type TextBlockParam, type TextDelta, type Tool, type ToolChoice, type ToolChoiceAny, type ToolChoiceAuto, type ToolChoiceTool, type ToolResultBlockParam, type ToolUseBlock, type ToolUseBlockParam, type Usage, type MessageCreateParams, type MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming, } from "./messages.js";
export { Messages, type Base64PDFSource, type CacheControlEphemeral, type ContentBlock, type ContentBlockDeltaEvent, type ContentBlockParam, type ContentBlockStartEvent, type ContentBlockStopEvent, type DocumentBlockParam, type ImageBlockParam, type InputJsonDelta, type InputJSONDelta, type Message, type MessageDeltaEvent, type MessageDeltaUsage, type MessageParam, type MessageStartEvent, type MessageStopEvent, type MessageStreamEvent, type MessageStreamParams, type MessageTokensCount, type Metadata, type Model, type RawContentBlockDeltaEvent, type RawContentBlockStartEvent, type RawContentBlockStopEvent, type RawMessageDeltaEvent, type RawMessageStartEvent, type RawMessageStopEvent, type RawMessageStreamEvent, type TextBlock, type TextBlockParam, type TextDelta, type Tool, type ToolChoice, type ToolChoiceAny, type ToolChoiceAuto, type ToolChoiceTool, type ToolResultBlockParam, type ToolUseBlock, type ToolUseBlockParam, type Usage, type MessageCreateParams, type MessageCreateParamsNonStreaming, type MessageCreateParamsStreaming, type MessageCountTokensParams, } from "./messages/messages.js";
export { ModelInfosPage, Models, type ModelInfo, type ModelListParams } from "./models.js";
//# sourceMappingURL=index.d.ts.map
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Messages = exports.Completions = exports.Beta = void 0;
exports.Models = exports.ModelInfosPage = exports.Messages = exports.Completions = exports.Beta = void 0;
__exportStar(require("./shared.js"), exports);
var beta_1 = require("./beta/beta.js");

@@ -9,4 +24,7 @@ Object.defineProperty(exports, "Beta", { enumerable: true, get: function () { return beta_1.Beta; } });

Object.defineProperty(exports, "Completions", { enumerable: true, get: function () { return completions_1.Completions; } });
var messages_1 = require("./messages.js");
var messages_1 = require("./messages/messages.js");
Object.defineProperty(exports, "Messages", { enumerable: true, get: function () { return messages_1.Messages; } });
var models_1 = require("./models.js");
Object.defineProperty(exports, "ModelInfosPage", { enumerable: true, get: function () { return models_1.ModelInfosPage; } });
Object.defineProperty(exports, "Models", { enumerable: true, get: function () { return models_1.Models; } });
//# sourceMappingURL=index.js.map

@@ -40,3 +40,3 @@ import { VERSION } from "./version.js";

async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
async function defaultParseResponse<T>(props: APIResponseProps): Promise<WithRequestID<T>> {
const { response } = props;

@@ -58,7 +58,7 @@ if (props.options.stream) {

if (response.status === 204) {
return null as T;
return null as WithRequestID<T>;
}
if (props.options.__binaryResponse) {
return response as unknown as T;
return response as unknown as WithRequestID<T>;
}

@@ -74,3 +74,3 @@

return json as T;
return _addRequestID(json as T, response);
}

@@ -82,5 +82,21 @@

// TODO handle blob, arraybuffer, other content types, etc.
return text as unknown as T;
return text as unknown as WithRequestID<T>;
}
type WithRequestID<T> =
T extends Array<any> | Response | AbstractPage<any> ? T
: T extends Record<string, any> ? T & { _request_id?: string | null }
: T;
function _addRequestID<T>(value: T, response: Response): WithRequestID<T> {
if (!value || typeof value !== 'object' || Array.isArray(value)) {
return value as WithRequestID<T>;
}
return Object.defineProperty(value, '_request_id', {
value: response.headers.get('request-id'),
enumerable: false,
}) as WithRequestID<T>;
}
/**

@@ -90,8 +106,10 @@ * A subclass of `Promise` providing additional helper methods

*/
export class APIPromise<T> extends Promise<T> {
private parsedPromise: Promise<T> | undefined;
export class APIPromise<T> extends Promise<WithRequestID<T>> {
private parsedPromise: Promise<WithRequestID<T>> | undefined;
constructor(
private responsePromise: Promise<APIResponseProps>,
private parseResponse: (props: APIResponseProps) => PromiseOrValue<T> = defaultParseResponse,
private parseResponse: (
props: APIResponseProps,
) => PromiseOrValue<WithRequestID<T>> = defaultParseResponse,
) {

@@ -108,3 +126,3 @@ super((resolve) => {

return new APIPromise(this.responsePromise, async (props) =>
transform(await this.parseResponse(props), props),
_addRequestID(transform(await this.parseResponse(props), props), props.response),
);

@@ -129,4 +147,7 @@ }

}
/**
* Gets the parsed response data and the raw `Response` instance.
* Gets the parsed response data, the raw `Response` instance and the ID of the request,
* returned vie the `request-id` header which is useful for debugging requests and resporting
* issues to Anthropic.
*

@@ -136,3 +157,2 @@ * If you just want to get the raw `Response` instance without parsing it,

*
*
* 👋 Getting the wrong TypeScript type for `Response`?

@@ -144,10 +164,10 @@ * Try setting `"moduleResolution": "NodeNext"` if you can,

*/
async withResponse(): Promise<{ data: T; response: Response }> {
async withResponse(): Promise<{ data: T; response: Response; request_id: string | null | undefined }> {
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
return { data, response };
return { data, response, request_id: response.headers.get('request-id') };
}
private parse(): Promise<T> {
private parse(): Promise<WithRequestID<T>> {
if (!this.parsedPromise) {
this.parsedPromise = this.responsePromise.then(this.parseResponse);
this.parsedPromise = this.responsePromise.then(this.parseResponse) as any as Promise<WithRequestID<T>>;
}

@@ -157,4 +177,4 @@ return this.parsedPromise;

override then<TResult1 = T, TResult2 = never>(
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
override then<TResult1 = WithRequestID<T>, TResult2 = never>(
onfulfilled?: ((value: WithRequestID<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,

@@ -167,7 +187,7 @@ ): Promise<TResult1 | TResult2> {

onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
): Promise<T | TResult> {
): Promise<WithRequestID<T> | TResult> {
return this.parse().catch(onrejected);
}
override finally(onfinally?: (() => void) | undefined | null): Promise<T> {
override finally(onfinally?: (() => void) | undefined | null): Promise<WithRequestID<T>> {
return this.parse().finally(onfinally);

@@ -551,15 +571,9 @@ }

return (
this.getRequestClient()
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
.fetch.call(undefined, url, { signal: controller.signal as any, ...options })
.finally(() => {
clearTimeout(timeout);
})
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
clearTimeout(timeout);
})
);
}
protected getRequestClient(): RequestClient {
return { fetch: this.fetch };
}
private shouldRetry(response: Response): boolean {

@@ -739,3 +753,9 @@ // Note this is not a standard header.

request,
async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options),
async (props) =>
new Page(
client,
props.response,
await defaultParseResponse(props),
props.options,
) as WithRequestID<PageClass>,
);

@@ -1008,4 +1028,4 @@ }

// https://stackoverflow.com/a/19709846
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {

@@ -1012,0 +1032,0 @@ return startsWithSchemeRegexp.test(url);

@@ -7,15 +7,17 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export class APIError extends AnthropicError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;
export class APIError<
TStatus extends number | undefined = number | undefined,
THeaders extends Headers | undefined = Headers | undefined,
TError extends Object | undefined = Object | undefined,
> extends AnthropicError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
readonly headers: THeaders;
/** JSON body of the response that caused the error */
readonly error: TError;
readonly request_id: string | null | undefined;
constructor(
status: number | undefined,
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
super(`${APIError.makeMessage(status, error, message)}`);

@@ -55,3 +57,3 @@ this.status = status;

): APIError {
if (!status) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });

@@ -98,5 +100,3 @@ }

export class APIUserAbortError extends APIError {
override readonly status: undefined = undefined;
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {

@@ -107,5 +107,3 @@ super(undefined, undefined, message || 'Request was aborted.', undefined);

export class APIConnectionError extends APIError {
override readonly status: undefined = undefined;
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {

@@ -125,30 +123,16 @@ super(undefined, undefined, message || 'Connection error.', undefined);

export class BadRequestError extends APIError {
override readonly status: 400 = 400;
}
export class BadRequestError extends APIError<400, Headers> {}
export class AuthenticationError extends APIError {
override readonly status: 401 = 401;
}
export class AuthenticationError extends APIError<401, Headers> {}
export class PermissionDeniedError extends APIError {
override readonly status: 403 = 403;
}
export class PermissionDeniedError extends APIError<403, Headers> {}
export class NotFoundError extends APIError {
override readonly status: 404 = 404;
}
export class NotFoundError extends APIError<404, Headers> {}
export class ConflictError extends APIError {
override readonly status: 409 = 409;
}
export class ConflictError extends APIError<409, Headers> {}
export class UnprocessableEntityError extends APIError {
override readonly status: 422 = 422;
}
export class UnprocessableEntityError extends APIError<422, Headers> {}
export class RateLimitError extends APIError {
override readonly status: 429 = 429;
}
export class RateLimitError extends APIError<429, Headers> {}
export class InternalServerError extends APIError {}
export class InternalServerError extends APIError<number, Headers> {}

@@ -17,10 +17,31 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

} from "./resources/completions.js";
import { ModelInfo, ModelInfosPage, ModelListParams, Models } from "./resources/models.js";
import {
AnthropicBeta,
Beta,
BetaAPIError,
BetaAuthenticationError,
BetaBillingError,
BetaError,
BetaErrorResponse,
BetaGatewayTimeoutError,
BetaInvalidRequestError,
BetaNotFoundError,
BetaOverloadedError,
BetaPermissionError,
BetaRateLimitError,
} from "./resources/beta/beta.js";
import {
Base64PDFSource,
CacheControlEphemeral,
ContentBlock,
ContentBlockDeltaEvent,
ContentBlockParam,
ContentBlockStartEvent,
ContentBlockStopEvent,
DocumentBlockParam,
ImageBlockParam,
InputJSONDelta,
Message,
MessageCountTokensParams,
MessageCreateParams,

@@ -36,2 +57,3 @@ MessageCreateParamsNonStreaming,

MessageStreamParams,
MessageTokensCount,
Messages,

@@ -59,16 +81,3 @@ Metadata,

Usage,
} from "./resources/messages.js";
import {
AnthropicBeta,
Beta,
BetaAPIError,
BetaAuthenticationError,
BetaError,
BetaErrorResponse,
BetaInvalidRequestError,
BetaNotFoundError,
BetaOverloadedError,
BetaPermissionError,
BetaRateLimitError,
} from "./resources/beta/beta.js";
} from "./resources/messages/messages.js";

@@ -187,3 +196,3 @@ export interface ClientOptions {

throw new Errors.AnthropicError(
"It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n\nTODO: link!\n",
"It looks like you're running in a browser-like environment.\n\nThis is disabled by default, as it risks exposing your secret API credentials to attackers.\nIf you understand the risks and have appropriate mitigations in place,\nyou can set the `dangerouslyAllowBrowser` option to `true`, e.g.,\n\nnew Anthropic({ apiKey, dangerouslyAllowBrowser: true });\n",
);

@@ -208,2 +217,3 @@ }

messages: API.Messages = new API.Messages(this);
models: API.Models = new API.Models(this);
beta: API.Beta = new API.Beta(this);

@@ -297,27 +307,7 @@

export const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
export {
AnthropicError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
APIUserAbortError,
NotFoundError,
ConflictError,
RateLimitError,
BadRequestError,
AuthenticationError,
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} from "./error.js";
export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;
Anthropic.Completions = Completions;
Anthropic.Messages = Messages;
Anthropic.Models = Models;
Anthropic.ModelInfosPage = ModelInfosPage;
Anthropic.Beta = Beta;
export declare namespace Anthropic {

@@ -339,6 +329,10 @@ export type RequestOptions = Core.RequestOptions;

Messages as Messages,
type Base64PDFSource as Base64PDFSource,
type CacheControlEphemeral as CacheControlEphemeral,
type ContentBlock as ContentBlock,
type ContentBlockDeltaEvent as ContentBlockDeltaEvent,
type ContentBlockParam as ContentBlockParam,
type ContentBlockStartEvent as ContentBlockStartEvent,
type ContentBlockStopEvent as ContentBlockStopEvent,
type DocumentBlockParam as DocumentBlockParam,
type ImageBlockParam as ImageBlockParam,

@@ -353,2 +347,3 @@ type InputJSONDelta as InputJSONDelta,

type MessageStreamEvent as MessageStreamEvent,
type MessageTokensCount as MessageTokensCount,
type Metadata as Metadata,

@@ -379,5 +374,13 @@ type Model as Model,

type MessageStreamParams as MessageStreamParams,
type MessageCountTokensParams as MessageCountTokensParams,
};
export {
Models as Models,
type ModelInfo as ModelInfo,
ModelInfosPage as ModelInfosPage,
type ModelListParams as ModelListParams,
};
export {
Beta as Beta,

@@ -387,4 +390,6 @@ type AnthropicBeta as AnthropicBeta,

type BetaAuthenticationError as BetaAuthenticationError,
type BetaBillingError as BetaBillingError,
type BetaError as BetaError,
type BetaErrorResponse as BetaErrorResponse,
type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
type BetaInvalidRequestError as BetaInvalidRequestError,

@@ -396,4 +401,34 @@ type BetaNotFoundError as BetaNotFoundError,

};
export type APIErrorObject = API.APIErrorObject;
export type AuthenticationError = API.AuthenticationError;
export type BillingError = API.BillingError;
export type ErrorObject = API.ErrorObject;
export type ErrorResponse = API.ErrorResponse;
export type GatewayTimeoutError = API.GatewayTimeoutError;
export type InvalidRequestError = API.InvalidRequestError;
export type NotFoundError = API.NotFoundError;
export type OverloadedError = API.OverloadedError;
export type PermissionError = API.PermissionError;
export type RateLimitError = API.RateLimitError;
}
export const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;
export { toFile, fileFromPath } from "./uploads.js";
export {
AnthropicError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
APIUserAbortError,
NotFoundError,
ConflictError,
RateLimitError,
BadRequestError,
AuthenticationError,
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} from "./error.js";
export default Anthropic;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../resource.js";
import * as ModelsAPI from "./models.js";
import { BetaModelInfo, BetaModelInfosPage, ModelListParams, Models } from "./models.js";
import * as MessagesAPI from "./messages/messages.js";

@@ -47,8 +49,6 @@ import {

} from "./messages/messages.js";
import * as PromptCachingAPI from "./prompt-caching/prompt-caching.js";
import { PromptCaching } from "./prompt-caching/prompt-caching.js";
export class Beta extends APIResource {
models: ModelsAPI.Models = new ModelsAPI.Models(this._client);
messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
promptCaching: PromptCachingAPI.PromptCaching = new PromptCachingAPI.PromptCaching(this._client);
}

@@ -76,8 +76,16 @@

export interface BetaBillingError {
message: string;
type: 'billing_error';
}
export type BetaError =
| BetaInvalidRequestError
| BetaAuthenticationError
| BetaBillingError
| BetaPermissionError
| BetaNotFoundError
| BetaRateLimitError
| BetaGatewayTimeoutError
| BetaAPIError

@@ -92,2 +100,8 @@ | BetaOverloadedError;

export interface BetaGatewayTimeoutError {
message: string;
type: 'timeout_error';
}
export interface BetaInvalidRequestError {

@@ -123,4 +137,5 @@ message: string;

Beta.Models = Models;
Beta.BetaModelInfosPage = BetaModelInfosPage;
Beta.Messages = Messages;
Beta.PromptCaching = PromptCaching;

@@ -132,4 +147,6 @@ export declare namespace Beta {

type BetaAuthenticationError as BetaAuthenticationError,
type BetaBillingError as BetaBillingError,
type BetaError as BetaError,
type BetaErrorResponse as BetaErrorResponse,
type BetaGatewayTimeoutError as BetaGatewayTimeoutError,
type BetaInvalidRequestError as BetaInvalidRequestError,

@@ -143,2 +160,9 @@ type BetaNotFoundError as BetaNotFoundError,

export {
Models as Models,
type BetaModelInfo as BetaModelInfo,
BetaModelInfosPage as BetaModelInfosPage,
type ModelListParams as ModelListParams,
};
export {
Messages as Messages,

@@ -185,4 +209,2 @@ type BetaBase64PDFBlock as BetaBase64PDFBlock,

};
export { PromptCaching as PromptCaching };
}

@@ -8,4 +8,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

type BetaAuthenticationError,
type BetaBillingError,
type BetaError,
type BetaErrorResponse,
type BetaGatewayTimeoutError,
type BetaInvalidRequestError,

@@ -17,2 +19,3 @@ type BetaNotFoundError,

} from "./beta.js";
export { BetaModelInfosPage, Models, type BetaModelInfo, type ModelListParams } from "./models.js";
export {

@@ -60,2 +63,1 @@ Messages,

} from "./messages/index.js";
export { PromptCaching } from "./prompt-caching/index.js";

@@ -7,4 +7,4 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as MessagesMessagesAPI from "./messages.js";
import * as MessagesAPI from "../../messages.js";
import * as BetaAPI from "../beta.js";
import * as MessagesAPI from "../../messages/messages.js";
import * as BatchesAPI from "./batches.js";

@@ -11,0 +11,0 @@ import {

@@ -7,3 +7,3 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as CompletionsAPI from "./completions.js";
import * as MessagesAPI from "./messages.js";
import * as MessagesAPI from "./messages/messages.js";
import { Stream } from "../streaming.js";

@@ -10,0 +10,0 @@

// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
export * from "./shared.js";
export {

@@ -8,4 +9,6 @@ Beta,

type BetaAuthenticationError,
type BetaBillingError,
type BetaError,
type BetaErrorResponse,
type BetaGatewayTimeoutError,
type BetaInvalidRequestError,

@@ -26,6 +29,10 @@ type BetaNotFoundError,

Messages,
type Base64PDFSource,
type CacheControlEphemeral,
type ContentBlock,
type ContentBlockDeltaEvent,
type ContentBlockParam,
type ContentBlockStartEvent,
type ContentBlockStopEvent,
type DocumentBlockParam,
type ImageBlockParam,

@@ -42,2 +49,3 @@ type InputJsonDelta,

type MessageStreamParams,
type MessageTokensCount,
type Metadata,

@@ -67,2 +75,4 @@ type Model,

type MessageCreateParamsStreaming,
} from "./messages.js";
type MessageCountTokensParams,
} from "./messages/messages.js";
export { ModelInfosPage, Models, type ModelInfo, type ModelListParams } from "./models.js";

@@ -1,1 +0,1 @@

export const VERSION = '0.32.1'; // x-release-please-version
export const VERSION = '0.33.0'; // x-release-please-version

@@ -1,2 +0,2 @@

export declare const VERSION = "0.32.1";
export declare const VERSION = "0.33.0";
//# sourceMappingURL=version.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
exports.VERSION = '0.32.1'; // x-release-please-version
exports.VERSION = '0.33.0'; // x-release-please-version
//# sourceMappingURL=version.js.map

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc