Chapter 10

Other Types

Additional type definitions for API keys, models, MCP servers, configuration, and sandbox settings.

ApiKeySourceType Alias

Indicates the source of the API key being used.

type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
ValueDescription
'user'API key from user settings
'project'API key from project configuration
'org'API key from organization
'temporary'Temporary API key for current session

SdkBetaType Alias

Available beta features that can be enabled via the betas option. See Beta headers for more information.

type SdkBeta = 'context-1m-2025-08-07';
ValueDescriptionCompatible Models
'context-1m-2025-08-07'Enables 1 million token context windowClaude Sonnet 4, Claude Sonnet 4.5

SlashCommandType

Information about an available slash command.

type SlashCommand = {
  name: string;
  description: string;
  argumentHint: string;
}
PropertyTypeDescription
namestringThe command name (without slash)
descriptionstringDescription of what the command does
argumentHintstringHint for expected arguments

ModelInfoType

Information about an available model.

type ModelInfo = {
  value: string;
  displayName: string;
  description: string;
}
PropertyTypeDescription
valuestringThe model identifier
displayNamestringHuman-readable name for display
descriptionstringDescription of the model capabilities

McpServerStatusType

Status of a connected MCP server.

type McpServerStatus = {
  name: string;
  status: 'connected' | 'failed' | 'needs-auth' | 'pending';
  serverInfo?: {
    name: string;
    version: string;
  };
}
PropertyTypeDescription
namestringThe MCP server name
status'connected' | 'failed' | 'needs-auth' | 'pending'Current connection status
serverInfoobject?Optional server metadata (name, version)

Status values:

'connected'Successfully connected
'failed'Connection failed
'needs-auth'Requires authentication
'pending'Connection in progress

AccountInfoType

Account information for the authenticated user.

type AccountInfo = {
  email?: string;
  organization?: string;
  subscriptionType?: string;
  tokenSource?: string;
  apiKeySource?: string;
}
PropertyTypeDescription
emailstring?User's email address
organizationstring?Organization name
subscriptionTypestring?Type of subscription
tokenSourcestring?Source of the authentication token
apiKeySourcestring?Source of the API key

ModelUsageType

Per-model usage statistics returned in result messages.

type ModelUsage = {
  inputTokens: number;
  outputTokens: number;
  cacheReadInputTokens: number;
  cacheCreationInputTokens: number;
  webSearchRequests: number;
  costUSD: number;
  contextWindow: number;
}
PropertyTypeDescription
inputTokensnumberNumber of input tokens used
outputTokensnumberNumber of output tokens generated
cacheReadInputTokensnumberTokens read from cache
cacheCreationInputTokensnumberTokens used to create cache
webSearchRequestsnumberNumber of web search requests
costUSDnumberTotal cost in USD
contextWindownumberContext window size used

ConfigScopeType Alias

Specifies the scope of configuration settings.

type ConfigScope = 'local' | 'user' | 'project';
ValueDescription
'local'Local (gitignored) settings
'user'Global user settings
'project'Project-specific settings

UsageType

Token usage statistics (from @anthropic-ai/sdk).

type Usage = {
  input_tokens: number | null;
  output_tokens: number | null;
  cache_creation_input_tokens?: number | null;
  cache_read_input_tokens?: number | null;
}
PropertyTypeDescription
input_tokensnumber | nullNumber of input tokens
output_tokensnumber | nullNumber of output tokens
cache_creation_input_tokensnumber | null?Tokens used to create cache
cache_read_input_tokensnumber | null?Tokens read from cache

NonNullableUsageType

A version of Usage with all nullable fields made non-nullable.

type NonNullableUsage = {
  [K in keyof Usage]: NonNullable<Usage[K]>;
}

CallToolResultType

MCP tool result type (from @modelcontextprotocol/sdk/types.js).

type CallToolResult = {
  content: Array<{
    type: 'text' | 'image' | 'resource';
    // Additional fields vary by type
  }>;
  isError?: boolean;
}
PropertyTypeDescription
contentArrayArray of content items (text, image, or resource)
isErrorboolean?Whether the result represents an error

AbortErrorClass

Custom error class for abort operations.

class AbortError extends Error {}

Sandbox Configuration

Configuration for sandbox behavior. Use this to enable command sandboxing and configure network restrictions programmatically.

SandboxSettingsType

Configuration for sandbox behavior.

type SandboxSettings = {
  enabled?: boolean;
  autoAllowBashIfSandboxed?: boolean;
  excludedCommands?: string[];
  allowUnsandboxedCommands?: boolean;
  network?: NetworkSandboxSettings;
  ignoreViolations?: SandboxIgnoreViolations;
  enableWeakerNestedSandbox?: boolean;
}
PropertyTypeDescription
enabledboolean?Enable sandbox mode
autoAllowBashIfSandboxedboolean?Auto-allow bash commands when sandboxed
excludedCommandsstring[]?Commands excluded from sandbox
allowUnsandboxedCommandsboolean?Allow commands to run outside sandbox
networkNetworkSandboxSettings?Network restriction settings
ignoreViolationsSandboxIgnoreViolations?Which violations to ignore
enableWeakerNestedSandboxboolean?Enable weaker nested sandbox mode