Skip to content

Commit

Permalink
feat(api): general availability updates
Browse files Browse the repository at this point in the history
The following APIs are now GA and have been moved out of the beta namespace:

- Prompt caching
- Token counting
- PDF Support
- The Batch API

This commit also adds new endpoints for listing available models.

https://docs.anthropic.com/en/release-notes/api
  • Loading branch information
RobertCraigie committed Dec 17, 2024
1 parent 82cac06 commit 93d1316
Show file tree
Hide file tree
Showing 25 changed files with 1,407 additions and 1,452 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 10
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-73443ebfebee64b8ec0ebbacd2521d6b6aa900e9526ec97abdcbcff0c0955d9b.yml
configured_endpoints: 19
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-be055148d227480fcacc9086c37ac8009dcb487731069ada51af35044f65bee4.yml
161 changes: 102 additions & 59 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,131 @@
# Anthropic

# Shared

Types:

- <code><a href="./src/resources/shared.ts">APIErrorObject</a></code>
- <code><a href="./src/resources/shared.ts">AuthenticationError</a></code>
- <code><a href="./src/resources/shared.ts">BillingError</a></code>
- <code><a href="./src/resources/shared.ts">ErrorObject</a></code>
- <code><a href="./src/resources/shared.ts">ErrorResponse</a></code>
- <code><a href="./src/resources/shared.ts">GatewayTimeoutError</a></code>
- <code><a href="./src/resources/shared.ts">InvalidRequestError</a></code>
- <code><a href="./src/resources/shared.ts">NotFoundError</a></code>
- <code><a href="./src/resources/shared.ts">OverloadedError</a></code>
- <code><a href="./src/resources/shared.ts">PermissionError</a></code>
- <code><a href="./src/resources/shared.ts">RateLimitError</a></code>

# Messages

Types:

- <code><a href="./src/resources/messages.ts">ContentBlock</a></code>
- <code><a href="./src/resources/messages.ts">ContentBlockDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">ContentBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">ContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">ContentBlockStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">ImageBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">InputJSONDelta</a></code>
- <code><a href="./src/resources/messages.ts">Message</a></code>
- <code><a href="./src/resources/messages.ts">MessageDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageDeltaUsage</a></code>
- <code><a href="./src/resources/messages.ts">MessageParam</a></code>
- <code><a href="./src/resources/messages.ts">MessageStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">MessageStreamEvent</a></code>
- <code><a href="./src/resources/messages.ts">Metadata</a></code>
- <code><a href="./src/resources/messages.ts">Model</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawContentBlockStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawMessageDeltaEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawMessageStartEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawMessageStopEvent</a></code>
- <code><a href="./src/resources/messages.ts">RawMessageStreamEvent</a></code>
- <code><a href="./src/resources/messages.ts">TextBlock</a></code>
- <code><a href="./src/resources/messages.ts">TextBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">TextDelta</a></code>
- <code><a href="./src/resources/messages.ts">Tool</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoice</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceAny</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceAuto</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceTool</a></code>
- <code><a href="./src/resources/messages.ts">ToolResultBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">ToolUseBlock</a></code>
- <code><a href="./src/resources/messages.ts">ToolUseBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">Usage</a></code>
- <code><a href="./src/resources/messages/messages.ts">Base64PDFSource</a></code>
- <code><a href="./src/resources/messages/messages.ts">CacheControlEphemeral</a></code>
- <code><a href="./src/resources/messages/messages.ts">ContentBlock</a></code>
- <code><a href="./src/resources/messages/messages.ts">ContentBlockDeltaEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">ContentBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">ContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">ContentBlockStopEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">DocumentBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">ImageBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">InputJSONDelta</a></code>
- <code><a href="./src/resources/messages/messages.ts">Message</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageDeltaEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageDeltaUsage</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageStartEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageStopEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageStreamEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">MessageTokensCount</a></code>
- <code><a href="./src/resources/messages/messages.ts">Metadata</a></code>
- <code><a href="./src/resources/messages/messages.ts">Model</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawContentBlockDeltaEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawContentBlockStartEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawContentBlockStopEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawMessageDeltaEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawMessageStartEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawMessageStopEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">RawMessageStreamEvent</a></code>
- <code><a href="./src/resources/messages/messages.ts">TextBlock</a></code>
- <code><a href="./src/resources/messages/messages.ts">TextBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">TextDelta</a></code>
- <code><a href="./src/resources/messages/messages.ts">Tool</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolChoice</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolChoiceAny</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolChoiceAuto</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolChoiceTool</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolResultBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolUseBlock</a></code>
- <code><a href="./src/resources/messages/messages.ts">ToolUseBlockParam</a></code>
- <code><a href="./src/resources/messages/messages.ts">Usage</a></code>

Methods:

- <code title="post /v1/messages">client.messages.<a href="./src/resources/messages.ts">create</a>({ ...params }) -> Message</code>
- <code title="post /v1/messages">client.messages.<a href="./src/resources/messages/messages.ts">create</a>({ ...params }) -> Message</code>
- <code title="post /v1/messages/count_tokens">client.messages.<a href="./src/resources/messages/messages.ts">countTokens</a>({ ...params }) -> MessageTokensCount</code>
- <code>client.messages.<a href="./src/resources/messages.ts">stream</a>(body, options?) -> MessageStream</code>

## Batches

Types:

- <code><a href="./src/resources/messages/batches.ts">MessageBatch</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchCanceledResult</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchErroredResult</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchExpiredResult</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchIndividualResponse</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchRequestCounts</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchResult</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchSucceededResult</a></code>

Methods:

- <code title="post /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">create</a>({ ...params }) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">retrieve</a>(messageBatchId) -> MessageBatch</code>
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">list</a>({ ...params }) -> MessageBatchesPage</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/resources/messages/batches.ts">cancel</a>(messageBatchId) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/resources/messages/batches.ts">results</a>(messageBatchId) -> Response</code>

# Models

Types:

- <code><a href="./src/resources/models.ts">ModelInfo</a></code>

Methods:

- <code title="get /v1/models/{model_id}">client.models.<a href="./src/resources/models.ts">retrieve</a>(modelId) -> ModelInfo</code>
- <code title="get /v1/models">client.models.<a href="./src/resources/models.ts">list</a>({ ...params }) -> ModelInfosPage</code>

# Beta

Types:

- <code><a href="./src/resources/beta/beta.ts">AnthropicBeta</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaAPIError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaAuthenticationError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaBillingError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaErrorResponse</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaGatewayTimeoutError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaInvalidRequestError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaNotFoundError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaOverloadedError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaPermissionError</a></code>
- <code><a href="./src/resources/beta/beta.ts">BetaRateLimitError</a></code>

## Models

Types:

- <code><a href="./src/resources/beta/models.ts">BetaModelInfo</a></code>

Methods:

- <code title="get /v1/models/{model_id}?beta=true">client.beta.models.<a href="./src/resources/beta/models.ts">retrieve</a>(modelId) -> BetaModelInfo</code>
- <code title="get /v1/models?beta=true">client.beta.models.<a href="./src/resources/beta/models.ts">list</a>({ ...params }) -> BetaModelInfosPage</code>

## Messages

Types:
Expand Down Expand Up @@ -125,26 +191,3 @@ Methods:
- <code title="get /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">list</a>({ ...params }) -> BetaMessageBatchesPage</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">cancel</a>(messageBatchId, { ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">results</a>(messageBatchId, { ...params }) -> Response</code>

## PromptCaching

### Messages

Types:

- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaCacheControlEphemeral</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaImageBlockParam</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaMessage</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaMessageParam</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaTextBlockParam</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaTool</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaToolResultBlockParam</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaToolUseBlockParam</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">PromptCachingBetaUsage</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">RawPromptCachingBetaMessageStartEvent</a></code>
- <code><a href="./src/resources/beta/prompt-caching/messages.ts">RawPromptCachingBetaMessageStreamEvent</a></code>

Methods:

- <code title="post /v1/messages?beta=prompt_caching">client.beta.promptCaching.messages.<a href="./src/resources/beta/prompt-caching/messages.ts">create</a>({ ...params }) -> PromptCachingBetaMessage</code>
- <code title="post /v1/messages?beta=prompt_caching">client.beta.promptCaching.messages.<a href="./src/resources/beta/prompt-caching/messages.ts">stream</a>({ ...params }) -> PromptCachingBetaMessageStream</code>
Empty file added examples/count-tokens.ts
Empty file.
65 changes: 51 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@ import {
CompletionCreateParamsStreaming,
Completions,
} from './resources/completions';
import { ModelInfo, ModelInfosPage, ModelListParams, Models } from './resources/models';
import {
AnthropicBeta,
Beta,
BetaAPIError,
BetaAuthenticationError,
BetaBillingError,
BetaError,
BetaErrorResponse,
BetaGatewayTimeoutError,
BetaInvalidRequestError,
BetaNotFoundError,
BetaOverloadedError,
BetaPermissionError,
BetaRateLimitError,
} from './resources/beta/beta';
import {
Base64PDFSource,
CacheControlEphemeral,
ContentBlock,
ContentBlockDeltaEvent,
ContentBlockParam,
ContentBlockStartEvent,
ContentBlockStopEvent,
DocumentBlockParam,
ImageBlockParam,
InputJSONDelta,
Message,
MessageCountTokensParams,
MessageCreateParams,
MessageCreateParamsNonStreaming,
MessageCreateParamsStreaming,
Expand All @@ -33,6 +53,7 @@ import {
MessageStopEvent,
MessageStreamEvent,
MessageStreamParams,
MessageTokensCount,
Messages,
Metadata,
Model,
Expand All @@ -55,20 +76,7 @@ import {
ToolUseBlock,
ToolUseBlockParam,
Usage,
} from './resources/messages';
import {
AnthropicBeta,
Beta,
BetaAPIError,
BetaAuthenticationError,
BetaError,
BetaErrorResponse,
BetaInvalidRequestError,
BetaNotFoundError,
BetaOverloadedError,
BetaPermissionError,
BetaRateLimitError,
} from './resources/beta/beta';
} from './resources/messages/messages';

export interface ClientOptions {
/**
Expand Down Expand Up @@ -202,6 +210,7 @@ export class Anthropic extends Core.APIClient {

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

protected override defaultQuery(): Core.DefaultQuery | undefined {
Expand Down Expand Up @@ -292,6 +301,8 @@ export class Anthropic extends Core.APIClient {

Anthropic.Completions = Completions;
Anthropic.Messages = Messages;
Anthropic.Models = Models;
Anthropic.ModelInfosPage = ModelInfosPage;
Anthropic.Beta = Beta;
export declare namespace Anthropic {
export type RequestOptions = Core.RequestOptions;
Expand All @@ -309,11 +320,14 @@ export declare namespace Anthropic {

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,
Expand All @@ -323,6 +337,7 @@ export declare namespace Anthropic {
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,
Expand All @@ -348,21 +363,43 @@ export declare namespace Anthropic {
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 const { HUMAN_PROMPT, AI_PROMPT } = Anthropic;

Expand Down
Loading

0 comments on commit 93d1316

Please sign in to comment.