messages.mjs•1.62 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../resource.mjs";
import * as BatchesAPI from "./batches.mjs";
import { Batches, BetaMessageBatchesPage, } from "./batches.mjs";
export class Messages extends APIResource {
constructor() {
super(...arguments);
this.batches = new BatchesAPI.Batches(this._client);
}
create(params, options) {
const { betas, ...body } = params;
return this._client.post('/v1/messages?beta=true', {
body,
timeout: this._client._options.timeout ?? 600000,
...options,
headers: {
...(betas?.toString() != null ? { 'anthropic-beta': betas?.toString() } : undefined),
...options?.headers,
},
stream: params.stream ?? false,
});
}
/**
* Count the number of tokens in a Message.
*
* The Token Count API can be used to count the number of tokens in a Message,
* including tools, images, and documents, without creating it.
*/
countTokens(params, options) {
const { betas, ...body } = params;
return this._client.post('/v1/messages/count_tokens?beta=true', {
body,
...options,
headers: {
'anthropic-beta': [...(betas ?? []), 'token-counting-2024-11-01'].toString(),
...options?.headers,
},
});
}
}
Messages.Batches = Batches;
Messages.BetaMessageBatchesPage = BetaMessageBatchesPage;
//# sourceMappingURL=messages.mjs.map