feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

View File

@@ -0,0 +1,304 @@
import { APIResource } from "../../core/resource.mjs";
import * as Shared from "../shared.mjs";
import * as MessagesAPI from "./messages.mjs";
import { APIPromise } from "../../core/api-promise.mjs";
import { Page, type PageParams, PagePromise } from "../../core/pagination.mjs";
import { RequestOptions } from "../../internal/request-options.mjs";
import { JSONLDecoder } from "../../internal/decoders/jsonl.mjs";
export declare class Batches extends APIResource {
/**
* Send a batch of Message creation requests.
*
* The Message Batches API can be used to process multiple Messages API requests at
* once. Once a Message Batch is created, it begins processing immediately. Batches
* can take up to 24 hours to complete.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.create({
* requests: [
* {
* custom_id: 'my-custom-id-1',
* params: {
* max_tokens: 1024,
* messages: [
* { content: 'Hello, world', role: 'user' },
* ],
* model: 'claude-opus-4-6',
* },
* },
* ],
* });
* ```
*/
create(body: BatchCreateParams, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* This endpoint is idempotent and can be used to poll for Message Batch
* completion. To access the results of a Message Batch, make a request to the
* `results_url` field in the response.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.retrieve(
* 'message_batch_id',
* );
* ```
*/
retrieve(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* List all Message Batches within a Workspace. Most recently created batches are
* returned first.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const messageBatch of client.messages.batches.list()) {
* // ...
* }
* ```
*/
list(query?: BatchListParams | null | undefined, options?: RequestOptions): PagePromise<MessageBatchesPage, MessageBatch>;
/**
* Delete a Message Batch.
*
* Message Batches can only be deleted once they've finished processing. If you'd
* like to delete an in-progress batch, you must first cancel it.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const deletedMessageBatch =
* await client.messages.batches.delete('message_batch_id');
* ```
*/
delete(messageBatchID: string, options?: RequestOptions): APIPromise<DeletedMessageBatch>;
/**
* Batches may be canceled any time before processing ends. Once cancellation is
* initiated, the batch enters a `canceling` state, at which time the system may
* complete any in-progress, non-interruptible requests before finalizing
* cancellation.
*
* The number of canceled requests is specified in `request_counts`. To determine
* which requests were canceled, check the individual results within the batch.
* Note that cancellation may not result in any canceled requests if they were
* non-interruptible.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.cancel(
* 'message_batch_id',
* );
* ```
*/
cancel(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* Streams the results of a Message Batch as a `.jsonl` file.
*
* Each line in the file is a JSON object containing the result of a single request
* in the Message Batch. Results are not guaranteed to be in the same order as
* requests. Use the `custom_id` field to match results to requests.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatchIndividualResponse =
* await client.messages.batches.results('message_batch_id');
* ```
*/
results(messageBatchID: string, options?: RequestOptions): Promise<JSONLDecoder<MessageBatchIndividualResponse>>;
}
export type MessageBatchesPage = Page<MessageBatch>;
export interface DeletedMessageBatch {
/**
* ID of the Message Batch.
*/
id: string;
/**
* Deleted object type.
*
* For Message Batches, this is always `"message_batch_deleted"`.
*/
type: 'message_batch_deleted';
}
export interface MessageBatch {
/**
* Unique object identifier.
*
* The format and length of IDs may change over time.
*/
id: string;
/**
* RFC 3339 datetime string representing the time at which the Message Batch was
* archived and its results became unavailable.
*/
archived_at: string | null;
/**
* RFC 3339 datetime string representing the time at which cancellation was
* initiated for the Message Batch. Specified only if cancellation was initiated.
*/
cancel_initiated_at: string | null;
/**
* RFC 3339 datetime string representing the time at which the Message Batch was
* created.
*/
created_at: string;
/**
* RFC 3339 datetime string representing the time at which processing for the
* Message Batch ended. Specified only once processing ends.
*
* Processing ends when every request in a Message Batch has either succeeded,
* errored, canceled, or expired.
*/
ended_at: string | null;
/**
* RFC 3339 datetime string representing the time at which the Message Batch will
* expire and end processing, which is 24 hours after creation.
*/
expires_at: string;
/**
* Processing status of the Message Batch.
*/
processing_status: 'in_progress' | 'canceling' | 'ended';
/**
* Tallies requests within the Message Batch, categorized by their status.
*
* Requests start as `processing` and move to one of the other statuses only once
* processing of the entire batch ends. The sum of all values always matches the
* total number of requests in the batch.
*/
request_counts: MessageBatchRequestCounts;
/**
* URL to a `.jsonl` file containing the results of the Message Batch requests.
* Specified only once processing ends.
*
* Results in the file are not guaranteed to be in the same order as requests. Use
* the `custom_id` field to match results to requests.
*/
results_url: string | null;
/**
* Object type.
*
* For Message Batches, this is always `"message_batch"`.
*/
type: 'message_batch';
}
export interface MessageBatchCanceledResult {
type: 'canceled';
}
export interface MessageBatchErroredResult {
error: Shared.ErrorResponse;
type: 'errored';
}
export interface MessageBatchExpiredResult {
type: 'expired';
}
/**
* This is a single line in the response `.jsonl` file and does not represent the
* response as a whole.
*/
export interface MessageBatchIndividualResponse {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
* matching results to requests, as results may be given out of request order.
*
* Must be unique for each request within the Message Batch.
*/
custom_id: string;
/**
* Processing result for this request.
*
* Contains a Message output if processing was successful, an error response if
* processing failed, or the reason why processing was not attempted, such as
* cancellation or expiration.
*/
result: MessageBatchResult;
}
export interface MessageBatchRequestCounts {
/**
* Number of requests in the Message Batch that have been canceled.
*
* This is zero until processing of the entire Message Batch has ended.
*/
canceled: number;
/**
* Number of requests in the Message Batch that encountered an error.
*
* This is zero until processing of the entire Message Batch has ended.
*/
errored: number;
/**
* Number of requests in the Message Batch that have expired.
*
* This is zero until processing of the entire Message Batch has ended.
*/
expired: number;
/**
* Number of requests in the Message Batch that are processing.
*/
processing: number;
/**
* Number of requests in the Message Batch that have completed successfully.
*
* This is zero until processing of the entire Message Batch has ended.
*/
succeeded: number;
}
/**
* Processing result for this request.
*
* Contains a Message output if processing was successful, an error response if
* processing failed, or the reason why processing was not attempted, such as
* cancellation or expiration.
*/
export type MessageBatchResult = MessageBatchSucceededResult | MessageBatchErroredResult | MessageBatchCanceledResult | MessageBatchExpiredResult;
export interface MessageBatchSucceededResult {
message: MessagesAPI.Message;
type: 'succeeded';
}
export interface BatchCreateParams {
/**
* List of requests for prompt completion. Each is an individual request to create
* a Message.
*/
requests: Array<BatchCreateParams.Request>;
}
export declare namespace BatchCreateParams {
interface Request {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
* matching results to requests, as results may be given out of request order.
*
* Must be unique for each request within the Message Batch.
*/
custom_id: string;
/**
* Messages API creation parameters for the individual request.
*
* See the [Messages API reference](https://docs.claude.com/en/api/messages) for
* full documentation on available parameters.
*/
params: MessagesAPI.MessageCreateParamsNonStreaming;
}
}
export interface BatchListParams extends PageParams {
}
export declare namespace Batches {
export { type DeletedMessageBatch as DeletedMessageBatch, type MessageBatch as MessageBatch, type MessageBatchCanceledResult as MessageBatchCanceledResult, type MessageBatchErroredResult as MessageBatchErroredResult, type MessageBatchExpiredResult as MessageBatchExpiredResult, type MessageBatchIndividualResponse as MessageBatchIndividualResponse, type MessageBatchRequestCounts as MessageBatchRequestCounts, type MessageBatchResult as MessageBatchResult, type MessageBatchSucceededResult as MessageBatchSucceededResult, type MessageBatchesPage as MessageBatchesPage, type BatchCreateParams as BatchCreateParams, type BatchListParams as BatchListParams, };
}
//# sourceMappingURL=batches.d.mts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"batches.d.mts","sourceRoot":"","sources":["../../src/resources/messages/batches.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,KAAK,MAAM;OACX,KAAK,WAAW;OAChB,EAAE,UAAU,EAAE;OACd,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE;OAEtC,EAAE,cAAc,EAAE;OAClB,EAAE,YAAY,EAAE;AAIvB,qBAAa,OAAQ,SAAQ,WAAW;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC;IAInF;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC;IAIpF;;;;;;;;;;;;;;OAcG;IACH,IAAI,CACF,KAAK,GAAE,eAAe,GAAG,IAAI,GAAG,SAAc,EAC9C,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,kBAAkB,EAAE,YAAY,CAAC;IAIhD;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,mBAAmB,CAAC;IAIzF;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC;IAIlF;;;;;;;;;;;;;;;OAeG;IACG,OAAO,CACX,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,cAAc,GACvB,OA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0,0 +1,304 @@
import { APIResource } from "../../core/resource.js";
import * as Shared from "../shared.js";
import * as MessagesAPI from "./messages.js";
import { APIPromise } from "../../core/api-promise.js";
import { Page, type PageParams, PagePromise } from "../../core/pagination.js";
import { RequestOptions } from "../../internal/request-options.js";
import { JSONLDecoder } from "../../internal/decoders/jsonl.js";
export declare class Batches extends APIResource {
/**
* Send a batch of Message creation requests.
*
* The Message Batches API can be used to process multiple Messages API requests at
* once. Once a Message Batch is created, it begins processing immediately. Batches
* can take up to 24 hours to complete.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.create({
* requests: [
* {
* custom_id: 'my-custom-id-1',
* params: {
* max_tokens: 1024,
* messages: [
* { content: 'Hello, world', role: 'user' },
* ],
* model: 'claude-opus-4-6',
* },
* },
* ],
* });
* ```
*/
create(body: BatchCreateParams, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* This endpoint is idempotent and can be used to poll for Message Batch
* completion. To access the results of a Message Batch, make a request to the
* `results_url` field in the response.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.retrieve(
* 'message_batch_id',
* );
* ```
*/
retrieve(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* List all Message Batches within a Workspace. Most recently created batches are
* returned first.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const messageBatch of client.messages.batches.list()) {
* // ...
* }
* ```
*/
list(query?: BatchListParams | null | undefined, options?: RequestOptions): PagePromise<MessageBatchesPage, MessageBatch>;
/**
* Delete a Message Batch.
*
* Message Batches can only be deleted once they've finished processing. If you'd
* like to delete an in-progress batch, you must first cancel it.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const deletedMessageBatch =
* await client.messages.batches.delete('message_batch_id');
* ```
*/
delete(messageBatchID: string, options?: RequestOptions): APIPromise<DeletedMessageBatch>;
/**
* Batches may be canceled any time before processing ends. Once cancellation is
* initiated, the batch enters a `canceling` state, at which time the system may
* complete any in-progress, non-interruptible requests before finalizing
* cancellation.
*
* The number of canceled requests is specified in `request_counts`. To determine
* which requests were canceled, check the individual results within the batch.
* Note that cancellation may not result in any canceled requests if they were
* non-interruptible.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.cancel(
* 'message_batch_id',
* );
* ```
*/
cancel(messageBatchID: string, options?: RequestOptions): APIPromise<MessageBatch>;
/**
* Streams the results of a Message Batch as a `.jsonl` file.
*
* Each line in the file is a JSON object containing the result of a single request
* in the Message Batch. Results are not guaranteed to be in the same order as
* requests. Use the `custom_id` field to match results to requests.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatchIndividualResponse =
* await client.messages.batches.results('message_batch_id');
* ```
*/
results(messageBatchID: string, options?: RequestOptions): Promise<JSONLDecoder<MessageBatchIndividualResponse>>;
}
export type MessageBatchesPage = Page<MessageBatch>;
export interface DeletedMessageBatch {
/**
* ID of the Message Batch.
*/
id: string;
/**
* Deleted object type.
*
* For Message Batches, this is always `"message_batch_deleted"`.
*/
type: 'message_batch_deleted';
}
export interface MessageBatch {
/**
* Unique object identifier.
*
* The format and length of IDs may change over time.
*/
id: string;
/**
* RFC 3339 datetime string representing the time at which the Message Batch was
* archived and its results became unavailable.
*/
archived_at: string | null;
/**
* RFC 3339 datetime string representing the time at which cancellation was
* initiated for the Message Batch. Specified only if cancellation was initiated.
*/
cancel_initiated_at: string | null;
/**
* RFC 3339 datetime string representing the time at which the Message Batch was
* created.
*/
created_at: string;
/**
* RFC 3339 datetime string representing the time at which processing for the
* Message Batch ended. Specified only once processing ends.
*
* Processing ends when every request in a Message Batch has either succeeded,
* errored, canceled, or expired.
*/
ended_at: string | null;
/**
* RFC 3339 datetime string representing the time at which the Message Batch will
* expire and end processing, which is 24 hours after creation.
*/
expires_at: string;
/**
* Processing status of the Message Batch.
*/
processing_status: 'in_progress' | 'canceling' | 'ended';
/**
* Tallies requests within the Message Batch, categorized by their status.
*
* Requests start as `processing` and move to one of the other statuses only once
* processing of the entire batch ends. The sum of all values always matches the
* total number of requests in the batch.
*/
request_counts: MessageBatchRequestCounts;
/**
* URL to a `.jsonl` file containing the results of the Message Batch requests.
* Specified only once processing ends.
*
* Results in the file are not guaranteed to be in the same order as requests. Use
* the `custom_id` field to match results to requests.
*/
results_url: string | null;
/**
* Object type.
*
* For Message Batches, this is always `"message_batch"`.
*/
type: 'message_batch';
}
export interface MessageBatchCanceledResult {
type: 'canceled';
}
export interface MessageBatchErroredResult {
error: Shared.ErrorResponse;
type: 'errored';
}
export interface MessageBatchExpiredResult {
type: 'expired';
}
/**
* This is a single line in the response `.jsonl` file and does not represent the
* response as a whole.
*/
export interface MessageBatchIndividualResponse {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
* matching results to requests, as results may be given out of request order.
*
* Must be unique for each request within the Message Batch.
*/
custom_id: string;
/**
* Processing result for this request.
*
* Contains a Message output if processing was successful, an error response if
* processing failed, or the reason why processing was not attempted, such as
* cancellation or expiration.
*/
result: MessageBatchResult;
}
export interface MessageBatchRequestCounts {
/**
* Number of requests in the Message Batch that have been canceled.
*
* This is zero until processing of the entire Message Batch has ended.
*/
canceled: number;
/**
* Number of requests in the Message Batch that encountered an error.
*
* This is zero until processing of the entire Message Batch has ended.
*/
errored: number;
/**
* Number of requests in the Message Batch that have expired.
*
* This is zero until processing of the entire Message Batch has ended.
*/
expired: number;
/**
* Number of requests in the Message Batch that are processing.
*/
processing: number;
/**
* Number of requests in the Message Batch that have completed successfully.
*
* This is zero until processing of the entire Message Batch has ended.
*/
succeeded: number;
}
/**
* Processing result for this request.
*
* Contains a Message output if processing was successful, an error response if
* processing failed, or the reason why processing was not attempted, such as
* cancellation or expiration.
*/
export type MessageBatchResult = MessageBatchSucceededResult | MessageBatchErroredResult | MessageBatchCanceledResult | MessageBatchExpiredResult;
export interface MessageBatchSucceededResult {
message: MessagesAPI.Message;
type: 'succeeded';
}
export interface BatchCreateParams {
/**
* List of requests for prompt completion. Each is an individual request to create
* a Message.
*/
requests: Array<BatchCreateParams.Request>;
}
export declare namespace BatchCreateParams {
interface Request {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
* matching results to requests, as results may be given out of request order.
*
* Must be unique for each request within the Message Batch.
*/
custom_id: string;
/**
* Messages API creation parameters for the individual request.
*
* See the [Messages API reference](https://docs.claude.com/en/api/messages) for
* full documentation on available parameters.
*/
params: MessagesAPI.MessageCreateParamsNonStreaming;
}
}
export interface BatchListParams extends PageParams {
}
export declare namespace Batches {
export { type DeletedMessageBatch as DeletedMessageBatch, type MessageBatch as MessageBatch, type MessageBatchCanceledResult as MessageBatchCanceledResult, type MessageBatchErroredResult as MessageBatchErroredResult, type MessageBatchExpiredResult as MessageBatchExpiredResult, type MessageBatchIndividualResponse as MessageBatchIndividualResponse, type MessageBatchRequestCounts as MessageBatchRequestCounts, type MessageBatchResult as MessageBatchResult, type MessageBatchSucceededResult as MessageBatchSucceededResult, type MessageBatchesPage as MessageBatchesPage, type BatchCreateParams as BatchCreateParams, type BatchListParams as BatchListParams, };
}
//# sourceMappingURL=batches.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"batches.d.ts","sourceRoot":"","sources":["../../src/resources/messages/batches.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,KAAK,MAAM;OACX,KAAK,WAAW;OAChB,EAAE,UAAU,EAAE;OACd,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE;OAEtC,EAAE,cAAc,EAAE;OAClB,EAAE,YAAY,EAA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;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,EAAE,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED,yBAAiB,iBAAiB,CAAC;IACjC,UAAiB,OAAO;QACtB;;;;;WAKG;QACH,SAAS,EAAE,MAAM,CAAC;QAElB;;;;;WAKG;QACH,MAAM,EAAE,WAAW,CAAC,+BAA+B,CAAC;KACrD;CACF;AAED,MAAM,WAAW,eAAgB,SAAQ,UAAU;CAAG;AAEtD,MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,OAAO,EACL,KAAK,mBAAmB,IAAI,mBAAmB,EAC/C,KAAK,YAAY,IAAI,YAAY,EACjC,KAAK,0BAA0B,IAAI,0BAA0B,EAC7D,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,8BAA8B,IAAI,8BAA8B,EACrE,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,2BAA2B,IAAI,2BAA2B,EAC/D,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,iBAAiB,IAAI,iBAAiB,EAC3C,KAAK,eAAe,IAAI,eAAe,GACxC,CAAC;CACH"}

View File

@@ -0,0 +1,153 @@
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Batches = void 0;
const resource_1 = require("../../core/resource.js");
const pagination_1 = require("../../core/pagination.js");
const headers_1 = require("../../internal/headers.js");
const jsonl_1 = require("../../internal/decoders/jsonl.js");
const error_1 = require("../../error.js");
const path_1 = require("../../internal/utils/path.js");
class Batches extends resource_1.APIResource {
/**
* Send a batch of Message creation requests.
*
* The Message Batches API can be used to process multiple Messages API requests at
* once. Once a Message Batch is created, it begins processing immediately. Batches
* can take up to 24 hours to complete.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.create({
* requests: [
* {
* custom_id: 'my-custom-id-1',
* params: {
* max_tokens: 1024,
* messages: [
* { content: 'Hello, world', role: 'user' },
* ],
* model: 'claude-opus-4-6',
* },
* },
* ],
* });
* ```
*/
create(body, options) {
return this._client.post('/v1/messages/batches', { body, ...options });
}
/**
* This endpoint is idempotent and can be used to poll for Message Batch
* completion. To access the results of a Message Batch, make a request to the
* `results_url` field in the response.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.retrieve(
* 'message_batch_id',
* );
* ```
*/
retrieve(messageBatchID, options) {
return this._client.get((0, path_1.path) `/v1/messages/batches/${messageBatchID}`, options);
}
/**
* List all Message Batches within a Workspace. Most recently created batches are
* returned first.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const messageBatch of client.messages.batches.list()) {
* // ...
* }
* ```
*/
list(query = {}, options) {
return this._client.getAPIList('/v1/messages/batches', (pagination_1.Page), { query, ...options });
}
/**
* Delete a Message Batch.
*
* Message Batches can only be deleted once they've finished processing. If you'd
* like to delete an in-progress batch, you must first cancel it.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const deletedMessageBatch =
* await client.messages.batches.delete('message_batch_id');
* ```
*/
delete(messageBatchID, options) {
return this._client.delete((0, path_1.path) `/v1/messages/batches/${messageBatchID}`, options);
}
/**
* Batches may be canceled any time before processing ends. Once cancellation is
* initiated, the batch enters a `canceling` state, at which time the system may
* complete any in-progress, non-interruptible requests before finalizing
* cancellation.
*
* The number of canceled requests is specified in `request_counts`. To determine
* which requests were canceled, check the individual results within the batch.
* Note that cancellation may not result in any canceled requests if they were
* non-interruptible.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.cancel(
* 'message_batch_id',
* );
* ```
*/
cancel(messageBatchID, options) {
return this._client.post((0, path_1.path) `/v1/messages/batches/${messageBatchID}/cancel`, options);
}
/**
* Streams the results of a Message Batch as a `.jsonl` file.
*
* Each line in the file is a JSON object containing the result of a single request
* in the Message Batch. Results are not guaranteed to be in the same order as
* requests. Use the `custom_id` field to match results to requests.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatchIndividualResponse =
* await client.messages.batches.results('message_batch_id');
* ```
*/
async results(messageBatchID, options) {
const batch = await this.retrieve(messageBatchID);
if (!batch.results_url) {
throw new error_1.AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
}
return this._client
.get(batch.results_url, {
...options,
headers: (0, headers_1.buildHeaders)([{ Accept: 'application/binary' }, options?.headers]),
stream: true,
__binaryResponse: true,
})
._thenUnwrap((_, props) => jsonl_1.JSONLDecoder.fromResponse(props.response, props.controller));
}
}
exports.Batches = Batches;
//# sourceMappingURL=batches.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"batches.js","sourceRoot":"","sources":["../../src/resources/messages/batches.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,qDAAkD;AAIlD,yDAA2E;AAC3E,uDAAsD;AAEtD,4DAA6D;AAC7D,0CAA6C;AAC7C,uDAAiD;AAEjD,MAAa,OAAQ,SAAQ,sBAAW;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,IAAuB,EAAE,OAAwB;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;;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,oBAAoB,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3E,MAAM,EAAE,IAAI;YACZ,gBAAgB,EAAE,IAAI;SACvB,CAAC;aACD,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,oBAAY,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAEvF,CAAC;IACJ,CAAC;CACF;AA5JD,0BA4JC"}

View File

@@ -0,0 +1,149 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { Page } from "../../core/pagination.mjs";
import { buildHeaders } from "../../internal/headers.mjs";
import { JSONLDecoder } from "../../internal/decoders/jsonl.mjs";
import { AnthropicError } from "../../error.mjs";
import { path } from "../../internal/utils/path.mjs";
export class Batches extends APIResource {
/**
* Send a batch of Message creation requests.
*
* The Message Batches API can be used to process multiple Messages API requests at
* once. Once a Message Batch is created, it begins processing immediately. Batches
* can take up to 24 hours to complete.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.create({
* requests: [
* {
* custom_id: 'my-custom-id-1',
* params: {
* max_tokens: 1024,
* messages: [
* { content: 'Hello, world', role: 'user' },
* ],
* model: 'claude-opus-4-6',
* },
* },
* ],
* });
* ```
*/
create(body, options) {
return this._client.post('/v1/messages/batches', { body, ...options });
}
/**
* This endpoint is idempotent and can be used to poll for Message Batch
* completion. To access the results of a Message Batch, make a request to the
* `results_url` field in the response.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.retrieve(
* 'message_batch_id',
* );
* ```
*/
retrieve(messageBatchID, options) {
return this._client.get(path `/v1/messages/batches/${messageBatchID}`, options);
}
/**
* List all Message Batches within a Workspace. Most recently created batches are
* returned first.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const messageBatch of client.messages.batches.list()) {
* // ...
* }
* ```
*/
list(query = {}, options) {
return this._client.getAPIList('/v1/messages/batches', (Page), { query, ...options });
}
/**
* Delete a Message Batch.
*
* Message Batches can only be deleted once they've finished processing. If you'd
* like to delete an in-progress batch, you must first cancel it.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const deletedMessageBatch =
* await client.messages.batches.delete('message_batch_id');
* ```
*/
delete(messageBatchID, options) {
return this._client.delete(path `/v1/messages/batches/${messageBatchID}`, options);
}
/**
* Batches may be canceled any time before processing ends. Once cancellation is
* initiated, the batch enters a `canceling` state, at which time the system may
* complete any in-progress, non-interruptible requests before finalizing
* cancellation.
*
* The number of canceled requests is specified in `request_counts`. To determine
* which requests were canceled, check the individual results within the batch.
* Note that cancellation may not result in any canceled requests if they were
* non-interruptible.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatch = await client.messages.batches.cancel(
* 'message_batch_id',
* );
* ```
*/
cancel(messageBatchID, options) {
return this._client.post(path `/v1/messages/batches/${messageBatchID}/cancel`, options);
}
/**
* Streams the results of a Message Batch as a `.jsonl` file.
*
* Each line in the file is a JSON object containing the result of a single request
* in the Message Batch. Results are not guaranteed to be in the same order as
* requests. Use the `custom_id` field to match results to requests.
*
* Learn more about the Message Batches API in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)
*
* @example
* ```ts
* const messageBatchIndividualResponse =
* await client.messages.batches.results('message_batch_id');
* ```
*/
async results(messageBatchID, options) {
const batch = await this.retrieve(messageBatchID);
if (!batch.results_url) {
throw new AnthropicError(`No batch \`results_url\`; Has it finished processing? ${batch.processing_status} - ${batch.id}`);
}
return this._client
.get(batch.results_url, {
...options,
headers: buildHeaders([{ Accept: 'application/binary' }, options?.headers]),
stream: true,
__binaryResponse: true,
})
._thenUnwrap((_, props) => JSONLDecoder.fromResponse(props.response, props.controller));
}
}
//# sourceMappingURL=batches.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"batches.mjs","sourceRoot":"","sources":["../../src/resources/messages/batches.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAIf,EAAE,IAAI,EAAgC;OACtC,EAAE,YAAY,EAAE;OAEhB,EAAE,YAAY,EAAE;OAChB,EAAE,cAAc,EAAE;OAClB,EAAE,IAAI,EAAE;AAEf,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,IAAuB,EAAE,OAAwB;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,cAAsB,EAAE,OAAwB;QACvD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAA,wBAAwB,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IACjF,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,IAAI,CACF,QAA4C,EAAE,EAC9C,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,sBAAsB,EAAE,CAAA,IAAkB,CAAA,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACpG,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,cAAsB,EAAE,OAAwB;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAA,wBAAwB,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,cAAsB,EAAE,OAAwB;QACrD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAA,wBAAwB,cAAc,SAAS,EAAE,OAAO,CAAC,CAAC;IACzF,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,OAAO,CACX,cAAsB,EACtB,OAAwB;QAExB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QAClD,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CACtB,yDAAyD,KAAK,CAAC,iBAAiB,MAAM,KAAK,CAAC,EAAE,EAAE,CACjG,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,OAAO;aAChB,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE;YACtB,GAAG,OAAO;YACV,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3E,MAAM,EAAE,IAAI;YACZ,gBAAgB,EAAE,IAAI;SACvB,CAAC;aACD,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAEvF,CAAC;IACJ,CAAC;CACF"}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/resources/messages/index.ts"],"names":[],"mappings":"OAEO,EACL,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,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oB,EACzB,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,KAAK,oCAAoC,EACzC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,oCAAoC,EACzC,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,GAC9B"}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/messages/index.ts"],"names":[],"mappings":"OAEO,EACL,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,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Ac,EACnB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC9B,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,KAAK,oCAAoC,EACzC,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,6BAA6B,EAClC,KAAK,oCAAoC,EACzC,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,GAC9B"}

View File

@@ -0,0 +1,9 @@
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Messages = exports.Batches = void 0;
var batches_1 = require("./batches.js");
Object.defineProperty(exports, "Batches", { enumerable: true, get: function () { return batches_1.Batches; } });
var messages_1 = require("./messages.js");
Object.defineProperty(exports, "Messages", { enumerable: true, get: function () { return messages_1.Messages; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/messages/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,wCAcmB;AAbjB,kGAAA,OAAO,OAAA;AAcT,0CA0KoB;AAzKlB,oGAAA,QAAQ,OAAA"}

View File

@@ -0,0 +1,4 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
export { Batches, } from "./batches.mjs";
export { Messages, } from "./messages.mjs";
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/resources/messages/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EACL,OAAO,GAaR;OACM,EACL,QAAQ,GAyKT"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,128 @@
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Messages = void 0;
const tslib_1 = require("../../internal/tslib.js");
const resource_1 = require("../../core/resource.js");
const headers_1 = require("../../internal/headers.js");
const stainless_helper_header_1 = require("../../lib/stainless-helper-header.js");
const MessageStream_1 = require("../../lib/MessageStream.js");
const parser_1 = require("../../lib/parser.js");
const BatchesAPI = tslib_1.__importStar(require("./batches.js"));
const batches_1 = require("./batches.js");
const constants_1 = require("../../internal/constants.js");
class Messages extends resource_1.APIResource {
constructor() {
super(...arguments);
this.batches = new BatchesAPI.Batches(this._client);
}
create(body, options) {
if (body.model in DEPRECATED_MODELS) {
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
}
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED &&
body.thinking &&
body.thinking.type === 'enabled') {
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
}
let timeout = this._client._options.timeout;
if (!body.stream && timeout == null) {
const maxNonstreamingTokens = constants_1.MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
}
// Collect helper info from tools and messages
const helperHeader = (0, stainless_helper_header_1.stainlessHelperHeader)(body.tools, body.messages);
return this._client.post('/v1/messages', {
body,
timeout: timeout ?? 600000,
...options,
headers: (0, headers_1.buildHeaders)([helperHeader, options?.headers]),
stream: body.stream ?? false,
});
}
/**
* Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
* the response will be automatically parsed and available in the `parsed_output` property of the message.
*
* @example
* ```ts
* const message = await client.messages.parse({
* model: 'claude-sonnet-4-5-20250929',
* max_tokens: 1024,
* messages: [{ role: 'user', content: 'What is 2+2?' }],
* output_config: {
* format: zodOutputFormat(z.object({ answer: z.number() })),
* },
* });
*
* console.log(message.parsed_output?.answer); // 4
* ```
*/
parse(params, options) {
return this.create(params, options).then((message) => (0, parser_1.parseMessage)(message, params, { logger: this._client.logger ?? console }));
}
/**
* Create a Message stream.
*
* If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
* the final message will include a `parsed_output` property with the parsed content.
*
* @example
* ```ts
* const stream = client.messages.stream({
* model: 'claude-sonnet-4-5-20250929',
* max_tokens: 1024,
* messages: [{ role: 'user', content: 'What is 2+2?' }],
* output_config: {
* format: zodOutputFormat(z.object({ answer: z.number() })),
* },
* });
*
* const message = await stream.finalMessage();
* console.log(message.parsed_output?.answer); // 4
* ```
*/
stream(body, options) {
return MessageStream_1.MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
}
/**
* 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.
*
* Learn more about token counting in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
*
* @example
* ```ts
* const messageTokensCount =
* await client.messages.countTokens({
* messages: [{ content: 'string', role: 'user' }],
* model: 'claude-opus-4-6',
* });
* ```
*/
countTokens(body, options) {
return this._client.post('/v1/messages/count_tokens', { body, ...options });
}
}
exports.Messages = Messages;
const DEPRECATED_MODELS = {
'claude-1.3': 'November 6th, 2024',
'claude-1.3-100k': 'November 6th, 2024',
'claude-instant-1.1': 'November 6th, 2024',
'claude-instant-1.1-100k': 'November 6th, 2024',
'claude-instant-1.2': 'November 6th, 2024',
'claude-3-sonnet-20240229': 'July 21st, 2025',
'claude-3-opus-20240229': 'January 5th, 2026',
'claude-2.1': 'July 21st, 2025',
'claude-2.0': 'July 21st, 2025',
'claude-3-7-sonnet-latest': 'February 19th, 2026',
'claude-3-7-sonnet-20250219': 'February 19th, 2026',
'claude-3-5-haiku-latest': 'February 19th, 2026',
'claude-3-5-haiku-20241022': 'February 19th, 2026',
};
const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-opus-4-6'];
Messages.Batches = batches_1.Batches;
//# sourceMappingURL=messages.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;AAGtF,qDAAkD;AAElD,uDAAsD;AAEtD,kFAA0E;AAC1E,8DAAwD;AACxD,gDAK0B;AAC1B,iEAAwC;AACxC,0CAcmB;AAGnB,2DAAqE;AAErE,MAAa,QAAS,SAAQ,sBAAW;IAAzC;;QACE,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAsJrE,CAAC;IAxH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AAC"}

View File

@@ -0,0 +1,123 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { buildHeaders } from "../../internal/headers.mjs";
import { stainlessHelperHeader } from "../../lib/stainless-helper-header.mjs";
import { MessageStream } from "../../lib/MessageStream.mjs";
import { parseMessage, } from "../../lib/parser.mjs";
import * as BatchesAPI from "./batches.mjs";
import { Batches, } from "./batches.mjs";
import { MODEL_NONSTREAMING_TOKENS } from "../../internal/constants.mjs";
export class Messages extends APIResource {
constructor() {
super(...arguments);
this.batches = new BatchesAPI.Batches(this._client);
}
create(body, options) {
if (body.model in DEPRECATED_MODELS) {
console.warn(`The model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://docs.anthropic.com/en/docs/resources/model-deprecations for more information.`);
}
if (body.model in MODELS_TO_WARN_WITH_THINKING_ENABLED &&
body.thinking &&
body.thinking.type === 'enabled') {
console.warn(`Using Claude with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://platform.claude.com/docs/en/build-with-claude/adaptive-thinking`);
}
let timeout = this._client._options.timeout;
if (!body.stream && timeout == null) {
const maxNonstreamingTokens = MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
}
// Collect helper info from tools and messages
const helperHeader = stainlessHelperHeader(body.tools, body.messages);
return this._client.post('/v1/messages', {
body,
timeout: timeout ?? 600000,
...options,
headers: buildHeaders([helperHeader, options?.headers]),
stream: body.stream ?? false,
});
}
/**
* Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
* the response will be automatically parsed and available in the `parsed_output` property of the message.
*
* @example
* ```ts
* const message = await client.messages.parse({
* model: 'claude-sonnet-4-5-20250929',
* max_tokens: 1024,
* messages: [{ role: 'user', content: 'What is 2+2?' }],
* output_config: {
* format: zodOutputFormat(z.object({ answer: z.number() })),
* },
* });
*
* console.log(message.parsed_output?.answer); // 4
* ```
*/
parse(params, options) {
return this.create(params, options).then((message) => parseMessage(message, params, { logger: this._client.logger ?? console }));
}
/**
* Create a Message stream.
*
* If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
* the final message will include a `parsed_output` property with the parsed content.
*
* @example
* ```ts
* const stream = client.messages.stream({
* model: 'claude-sonnet-4-5-20250929',
* max_tokens: 1024,
* messages: [{ role: 'user', content: 'What is 2+2?' }],
* output_config: {
* format: zodOutputFormat(z.object({ answer: z.number() })),
* },
* });
*
* const message = await stream.finalMessage();
* console.log(message.parsed_output?.answer); // 4
* ```
*/
stream(body, options) {
return MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
}
/**
* 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.
*
* Learn more about token counting in our
* [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
*
* @example
* ```ts
* const messageTokensCount =
* await client.messages.countTokens({
* messages: [{ content: 'string', role: 'user' }],
* model: 'claude-opus-4-6',
* });
* ```
*/
countTokens(body, options) {
return this._client.post('/v1/messages/count_tokens', { body, ...options });
}
}
const DEPRECATED_MODELS = {
'claude-1.3': 'November 6th, 2024',
'claude-1.3-100k': 'November 6th, 2024',
'claude-instant-1.1': 'November 6th, 2024',
'claude-instant-1.1-100k': 'November 6th, 2024',
'claude-instant-1.2': 'November 6th, 2024',
'claude-3-sonnet-20240229': 'July 21st, 2025',
'claude-3-opus-20240229': 'January 5th, 2026',
'claude-2.1': 'July 21st, 2025',
'claude-2.0': 'July 21st, 2025',
'claude-3-7-sonnet-latest': 'February 19th, 2026',
'claude-3-7-sonnet-20250219': 'February 19th, 2026',
'claude-3-5-haiku-latest': 'February 19th, 2026',
'claude-3-5-haiku-20241022': 'February 19th, 2026',
};
const MODELS_TO_WARN_WITH_THINKING_ENABLED = ['claude-opus-4-6'];
Messages.Batches = Batches;
//# sourceMappingURL=messages.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"messages.mjs","sourceRoot":"","sources":["../../src/resources/messages/messages.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,WAAW,EAAE;OAEf,EAAE,YAAY,EAAE;OAEhB,EAAE,qBAAqB,EAAE;OACzB,EAAE,aAAa,EAAE;OACjB,EACL,YAAY,GAIb;OACM,KAAK,UAAU;OACf,EAGL,OAAO,GAWR;OAGM,EAAE,yBAAyB,EAAE;AAEpC,MAAM,OAAO,QAAS,SAAQ,WAAW;IAAzC;;QACE,YAAO,GAAuB,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAsJrE,CAAC;IAxHC,MAAM,CACJ,IAAyB,EACzB,OAAwB;QAExB,IAAI,IAAI,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;YACpC,OAAO,CAAC,IAAI,CACV,cAAc,IAAI,CAAC,KAAK,iDACtB,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAC9B,gIAAgI,CACjI,CAAC;QACJ,CAAC;QACD,IACE,IAAI,CAAC,KAAK,IAAI,oCAAoC;YAClD,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAChC,CAAC;YACD,OAAO,CAAC,IAAI,CACV,qBAAqB,IAAI,CAAC,KAAK,oNAAoN,CACpP,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,GAAI,IAAI,CAAC,OAAe,CAAC,QAAQ,CAAC,OAAwB,CAAC;QACtE,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC;YACjF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,4BAA4B,CAAC,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC;QAC9F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