@varlabs/ai.anthropic
Version:
AI sdk for interfacing with AI models
465 lines • 14.4 kB
TypeScript
declare const aiModels: readonly ["claude-opus-4-20250514", "claude-opus-4-0", "claude-sonnet-4-20250514", "claude-sonnet-4-0", "claude-3-7-sonnet-20250219", "claude-3-7-sonnet-latest", "claude-3-5-haiku-20241022", "claude-3-5-haiku-latest", "claude-3-5-sonnet-20241022", "claude-3-5-sonnet-latest", "claude-3-5-sonnet-20240620", "claude-3-opus-20240229", "claude-3-opus-latest", "claude-3-sonnet-20240229", "claude-3-haiku-20240307"];
type Model = (typeof aiModels)[number] | string & {};
type Citation = {
cited_text: string;
document_index: number;
document_title: string;
end_char_index: number;
start_char_index: number;
type: 'char_location';
} | {
cited_text: string;
document_index: number;
document_title: string;
end_page_index: number;
start_page_index: number;
type: 'page_location';
} | {
cited_text: string;
document_index: number;
document_title: string;
end_block_index: number;
start_block_index: number;
type: 'content_block_location';
} | {
cited_text: string;
encrypted_index: string;
title?: string;
type: 'web_search_result_location';
url: string;
};
type CacheControl = {
type: 'ephemeral';
ttl?: '5m' | '1h';
};
type ToolParameterBase = {
type: 'string' | 'number' | 'boolean';
description?: string;
required?: boolean;
};
type ToolParameterArray = {
type: 'array';
items: (ToolParameterBase | ToolParameterObject | ToolParameterArray)[];
description?: string;
required?: boolean;
};
type ToolParameterObject = {
type: 'object';
properties: Record<string, ToolParameterObject | ToolParameterBase | ToolParameterArray>;
description?: string;
required?: boolean;
};
type ToolParameters = {
type: 'object';
properties: Record<string, ToolParameterObject | ToolParameterBase | ToolParameterArray>;
additionalProperties?: boolean;
};
type InferParameter<T> = T extends {
type: 'string';
} ? string : T extends {
type: 'number';
} ? number : T extends {
type: 'boolean';
} ? boolean : T extends {
type: 'array';
items: infer Items;
} ? InferArray<Items> : T extends {
type: 'object';
properties: infer Properties;
} ? Properties extends Record<string, any> ? InferObject<Properties> : never : never;
type InferArray<T> = T extends (infer U)[] ? InferParameter<U>[] : never;
type InferObject<T extends Record<string, any>> = {
[K in keyof T as T[K]['required'] extends true ? K : never]: InferParameter<T[K]>;
} & {
[K in keyof T as T[K]['required'] extends true ? never : K]?: InferParameter<T[K]>;
};
type InferToolParameters<T extends ToolParameters> = T extends {
properties: infer Props;
} ? Props extends Record<string, any> ? InferObject<Props> : never : never;
type CustomTool<TParams extends ToolParameters = any, TResult = any> = {
name: string;
type: 'custom';
description?: string;
cache_control?: CacheControl;
input_schema: TParams;
execute: (args: InferToolParameters<TParams>) => Promise<TResult>;
};
export declare const customTool: <TParams extends ToolParameters, TResult = any>(tool: CustomTool<TParams, TResult>) => CustomTool<TParams, TResult>;
type Tool = CustomTool | {
name: 'bash';
type: 'bash_20241022';
cache_control?: CacheControl;
} | {
name: 'bash';
type: 'bash_20250124';
cache_control?: CacheControl;
} | {
name: 'code_execution';
type: 'code_execution_20250522';
cache_control?: CacheControl;
} | {
name: 'computer';
display_height_px: number;
display_width_px: number;
type: 'computer_20241022';
cache_control?: CacheControl;
display_number?: number;
} | {
name: 'computer';
display_height_px: number;
display_width_px: number;
type: 'computer_20250124';
cache_control?: CacheControl;
display_number?: number;
} | {
name: 'str_replace_editor';
type: 'text_editor_20241022';
cache_control?: CacheControl;
} | {
name: 'str_replace_editor';
type: 'text_editor_20250124';
cache_control?: CacheControl;
} | {
name: 'str_replace_based_edit_tool';
type: 'text_editor_20250429';
cache_control?: CacheControl;
} | {
name: 'web_search';
type: 'web_search_20250305';
allowed_domains?: string[];
blocked_domains?: string[];
cache_control?: CacheControl;
max_uses?: number;
user_location?: {
type: 'approximate';
city?: string;
country?: string;
region?: string;
timezone?: string;
};
};
type TextContent = {
type: 'text';
text: string;
cache_control?: CacheControl;
citations?: Citation[];
};
type ImageContent = {
type: 'image';
cache_control?: CacheControl;
source: {
type: 'base64';
media_type: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
data: string;
} | {
type: 'url';
url: string;
} | {
type: 'file';
file_id: string;
};
};
type FunctionInput = {
input: {
model: Model;
messages: {
role: 'user' | 'assistant';
content: string | {
type: 'text';
text: string;
cache_control?: CacheControl;
citations?: Citation[];
} | ImageContent | {
type: 'document';
cache_control?: CacheControl;
citations?: Citation[];
context?: string;
title?: string;
source: {
type: 'base64';
media_type: 'application/pdf';
data: string;
} | {
type: 'text';
media_type: 'text/plain';
data: string;
} | {
type: 'content';
content: string | (TextContent | ImageContent)[];
} | {
type: 'url';
url: string;
} | {
type: 'file';
file_id: string;
};
} | {
type: 'thinking';
thinking: string;
signature: string;
} | {
type: 'redacted_thinking';
data: string;
} | {
type: 'tool_use';
id: string;
name: string;
input: any;
cache_control?: CacheControl;
} | {
type: 'tool_result';
tool_use_id: string;
is_error?: boolean;
cache_control?: CacheControl;
content?: string | (TextContent | ImageContent)[];
} | {
type: 'server_tool_use';
id: string;
name: 'web_search' | 'code_execution';
input: any;
cache_control?: CacheControl;
} | {
type: 'web_search_tool_result';
tool_use_id: string;
cache_control?: CacheControl;
content: {
type: 'web_search_tool_result_error';
error_code: 'invalid_tool_input' | 'unavailable' | 'max_uses_exceeded' | 'too_many_requests' | 'query_too_long';
} | {
encrypted_content: string;
title: string;
type: 'web_search_result';
url: string;
page_age?: string;
}[];
} | {
type: 'code_execution_tool_result';
tool_use_id: string;
cache_control?: CacheControl;
content: {
type: 'code_execution_tool_result_error';
error_code: 'invalid_tool_input' | 'unavailable' | 'max_uses_exceeded' | 'too_many_requests' | 'query_too_long';
} | {
type: 'code_execution_result';
stdout: string;
stderr: string;
return_code: number;
content: {
type: 'code_execution_output';
file_id: string;
}[];
};
} | {
type: 'mcp_tool_use';
id: string;
input: any;
name: string;
server_name: string;
cache_control?: CacheControl;
} | {
type: 'mcp_tool_result';
tool_use_id: string;
content: string | {
text: string;
type: 'text';
citations?: Citation[];
cache_control?: CacheControl;
};
cache_control?: CacheControl;
is_error?: boolean;
} | {
type: 'container_upload';
file_id: string;
cache_control?: CacheControl;
};
}[];
max_tokens: number;
container?: string;
mcp_servers?: {
name: string;
type: 'url';
url: string;
authorization_token?: string;
tool_configuration?: {
allowed_tools?: string[];
enabled?: boolean;
};
}[];
metadata?: {
user_id?: string;
};
service_tier?: 'auto' | 'standard_only';
stop_sequences?: string[];
system?: string | {
type: 'text';
text: string;
cache_control?: CacheControl;
citations?: Citation[];
};
temperature?: number;
thinking?: {
budget_tokens: number;
type: true;
} | {
type: false;
};
tool_choice?: {
type: 'auto';
disable_parallel_tool_user?: boolean;
} | {
type: 'any';
disable_parallel_tool_user?: boolean;
} | {
name: string;
type: 'tool';
disable_parallel_tool_user?: boolean;
} | {
type: 'none';
};
tools?: Tool[];
top_k?: number;
top_p?: number;
};
config?: {
fetchTimeout?: number;
};
};
type AnthropicResponse = {
id: string;
type: 'message';
role: 'assistant';
model: Model;
stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal';
stop_sequence: string;
container?: {
expires_at: string;
id: string;
};
usage: {
service_tier?: 'standard' | 'priority' | 'batch';
server_tool_use?: {
web_search_requests: number;
};
output_tokens: number;
input_tokens: number;
cache_read_input_tokens?: number;
cache_creation_input_tokens?: number;
cache_creation?: {
ephemeral_1h_input_tokens: number;
ephemeral_5m_input_tokens: number;
};
};
content: ({
type: 'text';
text: string;
} | {
type: 'thinking';
thinking: string;
signature: string;
} | {
type: 'redacted_thinking';
data: string;
} | {
type: 'tool_use';
id: string;
name: string;
input: any;
result?: any;
} | {
type: 'tool_result';
tool_use_id: string;
is_error?: boolean;
content?: string | (TextContent | ImageContent)[];
} | {
type: 'server_tool_use';
id: string;
name: 'web_search' | 'code_execution';
input: any;
} | {
type: 'web_search_tool_result';
tool_use_id: string;
content: {
type: 'web_search_tool_result_error';
error_code: 'invalid_tool_input' | 'unavailable' | 'max_uses_exceeded' | 'too_many_requests' | 'query_too_long';
} | {
encrypted_content: string;
title: string;
type: 'web_search_result';
url: string;
page_age?: string;
}[];
} | {
type: 'code_execution_tool_result';
tool_use_id: string;
content: {
type: 'code_execution_tool_result_error';
error_code: 'invalid_tool_input' | 'unavailable' | 'max_uses_exceeded' | 'too_many_requests' | 'query_too_long';
} | {
type: 'code_execution_result';
stdout: string;
stderr: string;
return_code: number;
content: {
type: 'code_execution_output';
file_id: string;
}[];
};
} | {
type: 'mcp_tool_use';
id: string;
input: any;
name: string;
server_name: string;
} | {
type: 'mcp_tool_result';
tool_use_id: string;
content: string | {
text: string;
type: 'text';
citations?: Citation[];
};
is_error?: boolean;
} | {
type: 'container_upload';
file_id: string;
})[];
};
declare const anthropicProvider: (config: {
config: {
apiKey: string;
baseUrl: string;
apiVersion: string;
};
}) => Omit<import("@varlabs/ai/provider").Provider<{
claude: {
messages: (input: FunctionInput, ctx: {
config: {
apiKey: string;
baseUrl: string;
apiVersion: string;
};
}) => Promise<AnthropicResponse>;
stream: (input: FunctionInput, ctx: {
config: {
apiKey: string;
baseUrl: string;
apiVersion: string;
};
}) => Promise<AsyncGenerator<AnthropicResponse, void, unknown>>;
};
}, {
config: {
apiKey: string;
baseUrl: string;
apiVersion: string;
};
}>, "models"> & {
models: {
claude: {
messages: (input: FunctionInput) => Promise<AnthropicResponse>;
stream: (input: FunctionInput) => Promise<AsyncGenerator<AnthropicResponse, void, unknown>>;
};
};
};
export default anthropicProvider;
//# sourceMappingURL=index.d.ts.map