Skip to content

Commit

Permalink
feat(bedrock): add beta.messages.create() method
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored and stainless-app[bot] committed Oct 22, 2024
1 parent 08a8928 commit faf8484
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/bedrock-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class AnthropicBedrock extends Core.APIClient {

messages: Resources.Messages = new Resources.Messages(this);
completions: Resources.Completions = new Resources.Completions(this);
beta: BetaResource = makeBetaResource(this);

protected override defaultQuery(): Core.DefaultQuery | undefined {
return this._options.defaultQuery;
Expand Down Expand Up @@ -120,6 +121,13 @@ export class AnthropicBedrock extends Core.APIClient {
if (!options.body['anthropic_version']) {
options.body['anthropic_version'] = DEFAULT_VERSION;
}

if (options.headers && !options.body['anthropic_beta']) {
const betas = Core.getHeader(options.headers, 'anthropic-beta');
if (betas != null) {
options.body['anthropic_beta'] = betas.split(',');
}
}
}

if (MODEL_ENDPOINTS.has(options.path) && options.method === 'post') {
Expand All @@ -143,3 +151,22 @@ export class AnthropicBedrock extends Core.APIClient {
return super.buildRequest(options);
}
}

/**
* The Bedrock API does not currently support prompt caching or the Batch API.
*/
type BetaResource = Omit<Resources.Beta, 'promptCaching' | 'messages'> & {
messages: Omit<Resources.Beta['messages'], 'batches'>;
};

function makeBetaResource(client: AnthropicBedrock): BetaResource {
const resource = new Resources.Beta(client);

// @ts-expect-error we're deleting non-optional properties
delete resource.promptCaching;

// @ts-expect-error we're deleting non-optional properties
delete resource.messages.batches;

return resource;
}

0 comments on commit faf8484

Please sign in to comment.