`generateText()`

generateText()

주어진 프롬프트에 대해 언어 모델을 사용해 텍스트를 생성하고 tool을 호출하는 함수예요.

자동화 작업처럼 상호작용이 필요 없는 사용 사례(이메일 초안 작성이나 웹 페이지 요약 등)와 tool을 사용하는 에이전트에 이상적입니다.

import { generateText } from 'ai';
__PROVIDER_IMPORT__;

const { text } = await generateText({
  model: __MODEL__,
  prompt: 'Invent a new holiday and describe its traditions.',
});

console.log(text);

runtimeContext, toolsContext, tool context, 민감한 컨텍스트 필터링에 대한 안내는 Runtime and Tool Context를 참고하세요.

실제 동작을 확인하려면 이 예제들을 살펴보세요.

출처: 문서

본문

Import

import { generateText } from "ai"

API 시그니처 (API Signature)

파라미터 (Parameters)

<PropertiesTable content={[ { name: 'model', type: 'LanguageModel', description: "사용할 언어 모델. 예: openai('gpt-6-astra')", }, { name: 'instructions', type: 'Instructions', description: '모델의 동작을 지정하는 데 사용할 지시문(instructions).', }, { name: 'prompt', type: 'string | Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>', description: '텍스트를 생성할 입력 프롬프트.', }, { name: 'messages', type: 'Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>', description: '대화를 나타내는 메시지 목록. useChat 훅의 UI 메시지를 자동으로 변환합니다.', properties: [ { type: 'SystemModelMessage', parameters: [ { name: 'role', type: "'system'", description: '시스템 메시지의 역할.', }, { name: 'content', type: 'string', description: '메시지의 내용.', }, ], }, { type: 'UserModelMessage', parameters: [ { name: 'role', type: "'user'", description: '사용자 메시지의 역할.', }, { name: 'content', type: 'string | Array<TextPart | ImagePart | FilePart>', description: '메시지의 내용.', properties: [ { type: 'TextPart', parameters: [ { name: 'type', type: "'text'", description: '메시지 part의 타입.', }, { name: 'text', type: 'string', description: '메시지 part의 텍스트 내용.', }, ], }, { type: 'ImagePart', parameters: [ { name: 'type', type: "'image'", description: '메시지 part의 타입.', }, { name: 'image', type: 'string | Uint8Array | Buffer | ArrayBuffer | URL', description: '메시지 part의 이미지 내용. 문자열은 base64 인코딩 콘텐츠, base64 데이터 URL 또는 http(s) URL입니다.', }, { name: 'mediaType', type: 'string', description: '이미지의 IANA 미디어 타입. 선택 사항.', isOptional: true, }, ], }, { type: 'FilePart', parameters: [ { name: 'type', type: "'file'", description: '메시지 part의 타입.', }, { name: 'data', type: 'string | Uint8Array | Buffer | ArrayBuffer | URL', description: '메시지 part의 파일 내용. 문자열은 base64 인코딩 콘텐츠, base64 데이터 URL 또는 http(s) URL입니다.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, ], }, ], }, { type: 'AssistantModelMessage', parameters: [ { name: 'role', type: "'assistant'", description: '어시스턴트 메시지의 역할.', }, { name: 'content', type: 'string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart>', description: '메시지의 내용.', properties: [ { type: 'TextPart', parameters: [ { name: 'type', type: "'text'", description: '메시지 part의 타입.', }, { name: 'text', type: 'string', description: '메시지 part의 텍스트 내용.', }, ], }, { type: 'ReasoningPart', parameters: [ { name: 'type', type: "'reasoning'", description: '메시지 part의 타입.', }, { name: 'text', type: 'string', description: 'reasoning 텍스트.', }, ], }, { type: 'ReasoningFilePart', parameters: [ { name: 'type', type: "'reasoning-file'", description: '메시지 part의 타입.', }, { name: 'data', type: 'string | Uint8Array | Buffer | ArrayBuffer | URL', description: '파일 데이터. 문자열은 base64 인코딩 콘텐츠, base64 데이터 URL 또는 http(s) URL입니다.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, { type: 'FilePart', parameters: [ { name: 'type', type: "'file'", description: '메시지 part의 타입.', }, { name: 'data', type: 'string | Uint8Array | Buffer | ArrayBuffer | URL', description: '메시지 part의 파일 내용. 문자열은 base64 인코딩 콘텐츠, base64 데이터 URL 또는 http(s) URL입니다.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, { name: 'filename', type: 'string', description: '파일의 이름.', isOptional: true, }, ], }, { type: 'ToolCallPart', parameters: [ { name: 'type', type: "'tool-call'", description: '메시지 part의 타입.', }, { name: 'toolCallId', type: 'string', description: 'tool 호출의 id.', }, { name: 'toolName', type: 'string', description: 'tool의 이름. 일반적으로 함수의 이름이 됩니다.', }, { name: 'input', type: 'object based on zod schema', description: '모델이 생성한, tool에서 사용할 입력(파라미터).', }, ], }, ], }, ], }, { type: 'ToolModelMessage', parameters: [ { name: 'role', type: "'tool'", description: '어시스턴트 메시지의 역할.', }, { name: 'content', type: 'Array', description: '메시지의 내용.', properties: [ { type: 'ToolResultPart', parameters: [ { name: 'type', type: "'tool-result'", description: '메시지 part의 타입.', }, { name: 'toolCallId', type: 'string', description: '결과가 대응하는 tool 호출의 id.', }, { name: 'toolName', type: 'string', description: '결과가 대응하는 tool의 이름.', }, { name: 'output', type: 'unknown', description: 'tool이 실행된 후 반환한 결과.', }, { name: 'isError', type: 'boolean', isOptional: true, description: '결과가 오류이거나 오류 메시지인지 여부.', }, ], }, ], }, ], }, ], }, { name: 'allowSystemInMessages', type: 'boolean', isOptional: true, description: 'prompt 또는 messages 필드에 시스템 메시지가 허용되는지 여부. 기본값은 false. instructions 옵션의 시스템 메시지는 항상 허용됩니다. 사용자 제어 메시지에서 이 옵션을 활성화하면 프롬프트 인젝션 위험이 생길 수 있습니다.', }, { name: 'tools', type: 'ToolSet', description: '모델이 접근하고 호출할 수 있는 tool. 모델이 tool 호출을 지원해야 합니다.', properties: [ { type: 'Tool', parameters: [ { name: 'description', isOptional: true, type: 'string | ((options: { context: CONTEXT; experimental_sandbox?: Experimental_SandboxSession }) => string)', description: 'tool의 목적에 대한 정보로, 모델이 언제 어떻게 사용할 수 있는지에 대한 세부 사항을 포함합니다. 고정 설명 문자열을 제공하거나, 각 모델 호출 전에 tool별 컨텍스트와 선택적 experimental 샌드박스로부터 설명을 파생하는 함수를 제공하세요.', }, { name: 'inputSchema', type: 'Zod Schema | JSON Schema', description: 'tool이 기대하는 입력의 스키마. 언어 모델이 이를 사용해 입력을 생성합니다. 또한 언어 모델 출력을 검증하는 데도 사용됩니다. 설명(description)을 사용해 입력을 언어 모델이 이해하기 쉽게 만드세요. Zod 스키마 또는 JSON 스키마(jsonSchema 함수 사용)를 전달할 수 있습니다.', }, { name: 'execute', isOptional: true, type: 'async (parameters: T, options: ToolExecutionOptions) => RESULT', description: 'tool 호출의 인자와 함께 호출되어 결과를 생성하는 async 함수. 제공하지 않으면 tool이 자동으로 실행되지 않습니다.', properties: [ { type: 'ToolExecutionOptions', parameters: [ { name: 'toolCallId', type: 'string', description: 'tool 호출의 ID. 예를 들어 스트림 데이터와 함께 tool 호출 관련 정보를 보낼 때 사용할 수 있습니다.', }, { name: 'messages', type: 'ModelMessage[]', description: 'tool 호출을 포함한 응답을 시작하기 위해 언어 모델로 보낸 메시지. 시스템 프롬프트와 tool 호출을 포함한 어시스턴트 응답은 포함하지 않습니다.', }, { name: 'abortSignal', type: 'AbortSignal', description: '전체 작업을 중단해야 함을 나타내는 선택적 abort signal.', }, ], }, ], }, ], }, ], }, { name: 'toolChoice', isOptional: true, type: '"auto" | "none" | "required" | { "type": "tool", "toolName": string }', description: 'tool 선택 설정. tool을 어떻게 선택해 실행할지 지정합니다. 기본값은 "auto". "none"은 tool 실행을 비활성화합니다. "required"는 tool 실행을 요구합니다. { "type": "tool", "toolName": string }은 특정 tool을 실행하도록 지정합니다.', }, { name: 'maxOutputTokens', type: 'number', isOptional: true, description: '생성할 최대 토큰 수.', }, { name: 'temperature', type: 'number', isOptional: true, description: 'Temperature 설정. 값은 프로바이더로 전달됩니다. 범위는 프로바이더와 모델에 따라 다릅니다. temperature 또는 topP 중 하나를 설정하는 것을 권장하며, 둘 다 설정하는 것은 권장하지 않습니다.', }, { name: 'topP', type: 'number', isOptional: true, description: 'Nucleus sampling. 값은 프로바이더로 전달됩니다. 범위는 프로바이더와 모델에 따라 다릅니다. temperature 또는 topP 중 하나를 설정하는 것을 권장하며, 둘 다 설정하는 것은 권장하지 않습니다.', }, { name: 'topK', type: 'number', isOptional: true, description: '후속 토큰마다 상위 K개 옵션에서만 샘플링합니다. "long tail" 저확률 응답을 제거하는 데 사용됩니다. 고급 사용 사례에만 권장됩니다. 보통 temperature만 사용하면 됩니다.', }, { name: 'presencePenalty', type: 'number', isOptional: true, description: 'Presence penalty 설정. 모델이 프롬프트에 이미 있는 정보를 반복할 가능성에 영향을 줍니다. 값은 프로바이더로 전달됩니다. 범위는 프로바이더와 모델에 따라 다릅니다.', }, { name: 'frequencyPenalty', type: 'number', isOptional: true, description: 'Frequency penalty 설정. 모델이 같은 단어나 구를 반복해서 사용할 가능성에 영향을 줍니다. 값은 프로바이더로 전달됩니다. 범위는 프로바이더와 모델에 따라 다릅니다.', }, { name: 'stopSequences', type: 'string[]', isOptional: true, description: '텍스트 생성을 중단시킬 시퀀스. 모델이 이 시퀀스 중 하나를 생성하면 추가 텍스트 생성을 중단합니다.', }, { name: 'seed', type: 'number', isOptional: true, description: '무작위 샘플링에 사용할 seed(정수). 설정하고 모델이 지원하면 호출이 결정론적 결과를 생성합니다.', }, { name: 'reasoning', type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'", isOptional: true, description: "모델이 응답을 생성하기 전에 수행할 reasoning 양을 제어합니다. 생략하면 프로바이더의 기본 동작이 사용됩니다. 'provider-default'는 프로바이더 기본값을 명시적으로 요청합니다. reasoning을 지원하지 않는 프로바이더는 경고를 발생시킵니다. reasoning 관련 providerOptions도 설정하면 그것이 우선하며 이 파라미터는 무시됩니다. 프로바이더별 매핑 세부 사항은 reasoning guide를 참고하세요.", }, { name: 'maxRetries', type: 'number', isOptional: true, description: '최대 재시도 횟수. 0으로 설정하면 재시도를 비활성화합니다. 기본값: 2.', }, { name: 'abortSignal', type: 'AbortSignal', isOptional: true, description: '호출을 취소하는 데 사용할 수 있는 선택적 abort signal.', }, { name: 'timeout', type: 'number | { totalMs?: number; stepMs?: number; toolMs?: number; tools?: { [toolName]Ms?: number } }', isOptional: true, description: '밀리초 단위의 타임아웃. 숫자 또는 totalMs, stepMs, toolMs, tools 속성을 가진 객체로 지정할 수 있습니다. totalMs는 전체 호출의 총 타임아웃을 설정합니다. stepMs는 각 단계(LLM 호출)의 타임아웃을 설정합니다. toolMs는 모든 tool 실행의 기본 타임아웃을 설정합니다. tools는 {toolName}Ms 패턴(예: weatherMs, slowApiMs)을 사용해 tool별 타임아웃 오버라이드를 설정하며, toolMs보다 우선합니다. tool 이름은 자동 완성을 위해 타입 검사됩니다. tool이 타임아웃보다 오래 걸리면 중단되고 tool-error를 반환해 모델이 응답하거나 재시도할 수 있게 합니다. abortSignal과 함께 사용할 수 있습니다.', }, { name: 'headers', type: 'Record<string, string | undefined>', isOptional: true, description: '요청과 함께 보낼 추가 HTTP 헤더. HTTP 기반 프로바이더에만 적용됩니다.', }, { name: 'telemetry', type: 'TelemetryOptions', isOptional: true, description: '텔레메트리 설정.', properties: [ { type: 'TelemetryOptions', parameters: [ { name: 'isEnabled', type: 'boolean', isOptional: true, description: '텔레메트리 활성화 또는 비활성화. 기본적으로 활성화됩니다. false로 설정하면 옵트아웃됩니다.', }, { name: 'recordInputs', type: 'boolean', isOptional: true, description: '입력 기록 활성화 또는 비활성화. 기본적으로 활성화됩니다.', }, { name: 'recordOutputs', type: 'boolean', isOptional: true, description: '출력 기록 활성화 또는 비활성화. 기본적으로 활성화됩니다.', }, { name: 'functionId', type: 'string', isOptional: true, description: '이 함수의 식별자. 함수별로 텔레메트리 데이터를 그룹화하는 데 사용됩니다.', }, { name: 'includeRuntimeContext', type: '{ [KEY in keyof CONTEXT]?: boolean }', isOptional: true, description: '텔레메트리에 포함할 최상위 런타임 컨텍스트 속성. true로 명시적으로 설정되지 않은 런타임 컨텍스트 속성은 제외됩니다. 수명주기 콜백과 반환 결과는 여전히 전체 runtimeContext를 받습니다.', }, { name: 'includeToolsContext', type: '{ [TOOL_NAME in keyof InferToolSetContext]?: { [KEY in keyof InferToolSetContext[TOOL_NAME]]?: boolean } }', isOptional: true, description: '텔레메트리에 포함할 최상위 tool 컨텍스트 속성으로, tool별로 설정합니다. true로 명시적으로 설정되지 않은 tool 컨텍스트 속성은 제외됩니다. 수명주기 콜백과 반환 결과는 여전히 전체 toolsContext를 받습니다.', }, { name: 'integrations', isOptional: true, type: 'Telemetry | Telemetry[]', description: '수명주기 이벤트를 받는 호출별 텔레메트리 통합. 제공하면 이 호출에 대해 전역으로 등록된 통합을 대체합니다.', }, ], }, ], }, { name: 'providerOptions', type: 'Record<string,JSONObject> | undefined', isOptional: true, description: '프로바이더별 옵션. 바깥쪽 키는 프로바이더 이름입니다. 안쪽 값은 메타데이터입니다. 세부 사항은 프로바이더에 따라 다릅니다.', }, { name: 'activeTools', type: 'ActiveTools', isOptional: true, description: '결과의 tool 호출 및 결과 타입을 바꾸지 않고 모델이 호출할 수 있는 tool을 제한합니다. 기본적으로 모든 tool이 활성화됩니다. tool 이름은 tool 세트의 문자열 키로 제한됩니다.', }, { name: 'toolOrder', type: 'ToolOrder', isOptional: true, description: 'tool을 프로바이더로 보내는 순서를 제어합니다. 목록은 부분적일 수 있습니다. toolOrder에 나열되지 않은 tool은 나열된 tool 뒤에 알파벳순으로 정렬되어 보내집니다. tool 이름은 tool 세트의 문자열 키로 제한됩니다.', }, { name: 'toolApproval', type: 'ToolApprovalConfiguration<TOOLS, RUNTIME_CONTEXT>', isOptional: true, description: "이 호출에 대한 승인 구성. GenericToolApprovalFunction을 전달하면 toolCall, tools, toolsContext, messages, runtimeContext로 모든 tool 호출을 하나의 콜백에서 처리하고, 각 키가 상태('not-applicable', 'approved', 'denied', 'user-approval'), { type: 'denied', reason: 'blocked by policy' } 같은 객체 형태, 또는 tool 입력과 toolCallId, messages, toolContext, runtimeContext 옵션(abortSignal 없이 context가 toolContext로 이름이 바뀐 tool 실행 옵션과 같은 형태)을 받는 SingleToolApprovalFunction을 포함하는 tool별 객체를 전달할 수 있습니다. RUNTIME_CONTEXT 타입 파라미터는 호출의 runtimeContext와 일치합니다. GenericToolApprovalFunction 또는 SingleToolApprovalFunction은 'not-applicable'과 같은 효과를 위해 undefined를 반환할 수 있습니다. 'not-applicable'은 기본 실행 경로이며 승인 메타데이터 없이 tool을 실행합니다. 출력에 명시적인 자동 승인 요청/응답 part를 원할 때 'approved', 'denied' 또는 그 객체 형태를 사용하세요. 객체 상태에는 reason을 포함할 수 있습니다. 자동 승인/거부는 이를 승인 응답으로 전달하고, 수동 사용자 승인은 이를 인간 승인자를 위한 승인 요청으로 전달합니다. 이 설정은 tool의 needsApproval 기본값보다 우선합니다.", }, { name: 'experimental_toolCallers', type: 'Experimental_ToolCallers', isOptional: true, description: "어떤 호출자 tool이 각 tool을 호출할 수 있는지 구성합니다. 콜백은 tools 세트에서 호출자 가능 tool의 타입 지정 참조를 받고, 피호출자 tool 이름을 키로 하는 객체를 반환합니다. 'direct'를 포함하면 설정된 tool이 모델에 의해 직접 호출 가능하도록 유지합니다. 로컬 전용 피호출자(callees)는 직접 모델 호출에서 숨겨지고 각 생성 단계에서 로컬 호출자에 바인딩됩니다. 프로바이더 호출자 참조는 프로바이더 고유의 허용 호출자 옵션으로 변환됩니다. 항목이 없는 tool은 기존의 직접 tool 호출 동작을 유지합니다.", }, { name: 'experimental_refineToolInput', type: 'ToolInputRefinement', isOptional: true, description: '파싱된 tool 입력을 정제하는 함수에 대한 tool 이름 매핑. 각 함수는 해당 tool의 타입 지정 입력을 받고 같은 입력 타입 형태를 반환해야 합니다. 정제된 입력은 tool 실행, 출력 part, 수명주기 콜백, 텔레메트리에 사용됩니다.', }, { name: 'stopWhen', type: 'StopCondition | Array<StopCondition>', isOptional: true, description: '마지막 step에 tool 결과가 있을 때 생성을 중단하는 조건. 조건이 배열이면 그중 하나라도 충족되면 생성을 중단합니다. 기본값: isStepCount(1).', }, { name: 'prepareStep', type: '(options: PrepareStepOptions) => PrepareStepResult | Promise<PrepareStepResult>', isOptional: true, description: '단계별로 다른 설정을 제공하는 데 사용할 수 있는 선택적 함수. 각 step에 대해 모델, 모델 호출 설정, tool 선택, 활성 tool, 지시문, 입력 메시지, experimental 샌드박스를 수정할 수 있습니다.', properties: [ { type: 'PrepareStepFunction', parameters: [ { name: 'options', type: 'object', description: '단계의 옵션.', properties: [ { type: 'PrepareStepOptions', parameters: [ { name: 'steps', type: 'Array<StepResult>', description: '지금까지 실행된 단계들.', }, { name: 'stepNumber', type: 'number', description: '실행 중인 단계의 번호.', }, { name: 'model', type: 'LanguageModel', description: '사용 중인 모델.', }, { name: 'instructions', type: 'Instructions | undefined', description: '현재 step에 대해 모델로 보낼 지시문. prepareStep이 instructions 오버라이드를 반환하면 해당 지시문이 이후 단계로 전달됩니다.', }, { name: 'initialInstructions', type: 'Instructions | undefined', description: 'generateText 또는 streamText에 전달된 초기 지시문.', }, { name: 'messages', type: 'Array', description: '현재 step에 대해 모델로 보낼 메시지. prepareStep이 messages 오버라이드를 반환하면 해당 메시지가 이후 단계로 전달됩니다.', }, { name: 'runtimeContext', type: 'CONTEXT', isOptional: true, description: 'runtimeContext 설정을 통해 전달된 공유 런타임 컨텍스트.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'toolsContext 설정을 통해 전달된 tool별 컨텍스트 맵.', }, { name: 'experimental_sandbox', type: 'Experimental_SandboxSession | undefined', isOptional: true, description: 'experimental_sandbox 설정을 통해 전달된 experimental 샌드박스 환경.', }, ], }, ], }, ], }, { type: 'PrepareStepResult', description: '현재 단계의 설정을 수정할 수 있는 반환 값.', parameters: [ { name: 'model', type: 'LanguageModel', isOptional: true, description: '이 step에 사용할 LanguageModel 인스턴스를 선택적으로 오버라이드합니다.', }, { name: 'maxOutputTokens', type: 'number', isOptional: true, description: '이 step에 생성할 최대 토큰 수. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'temperature', type: 'number', isOptional: true, description: '이 step의 temperature. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'topP', type: 'number', isOptional: true, description: '이 step의 nucleus sampling 값. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'topK', type: 'number', isOptional: true, description: '이 step의 top-K 샘플링 값. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'presencePenalty', type: 'number', isOptional: true, description: '이 step의 presence penalty. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'frequencyPenalty', type: 'number', isOptional: true, description: '이 step의 frequency penalty. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'stopSequences', type: 'string[]', isOptional: true, description: '이 step의 중지 시퀀스. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'seed', type: 'number', isOptional: true, description: '이 step의 무작위 샘플링 seed. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'reasoning', type: 'LanguageModelV4CallOptions["reasoning"]', isOptional: true, description: '이 step의 reasoning 노력. 생략하거나 undefined면 최상위 값을 사용합니다.', }, { name: 'toolChoice', type: 'ToolChoice', isOptional: true, description: '이 step에 대해 모델이 호출해야 할 tool을 선택적으로 설정하거나 tool 호출 구성을 제공합니다.', }, { name: 'activeTools', type: 'ActiveTools', isOptional: true, description: '제공하면 이 step에서 이 tool들만 활성화/사용 가능합니다.', }, { name: 'toolOrder', type: 'ToolOrder', isOptional: true, description: '제공하면 이 step에 대해 tool을 프로바이더로 보내는 순서를 오버라이드합니다. 나열되지 않은 tool은 알파벳순으로 추가됩니다.', }, { name: 'instructions', type: 'Instructions', isOptional: true, description: '이 step에 대해 모델로 보낼 지시문을 선택적으로 오버라이드합니다. prepareStep이 다른 instructions 또는 system 오버라이드를 반환할 때까지 해당 오버라이드가 이후 단계로 전달됩니다.', }, { name: 'messages', type: 'Array', isOptional: true, description: '이 step에 대해 모델로 보낼 전체 메시지 세트를 선택적으로 오버라이드합니다.', }, { name: 'runtimeContext', type: 'CONTEXT', isOptional: true, description: '공유 런타임 컨텍스트. 변경하면 이 step과 이후 모든 step에 영향을 줍니다.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'tool별 컨텍스트 맵. 변경하면 이 step과 이후 모든 step의 tool별 컨텍스트에 영향을 줍니다.', }, { name: 'experimental_sandbox', type: 'Experimental_SandboxSession', isOptional: true, description: '이 step의 experimental 샌드박스 환경. 변경하면 이 step에서만 tool 실행에 영향을 줍니다.', }, { name: 'providerOptions', type: 'ProviderOptions', isOptional: true, description: '이 step에 대한 추가 프로바이더별 옵션. Anthropic 코드 실행용 컨테이너 ID 같은 프로바이더별 구성을 전달하는 데 사용할 수 있습니다.', }, ], }, ], }, { name: 'runtimeContext', type: 'CONTEXT', isOptional: true, description: 'prepareStep와 수명주기 콜백에 전달되는 사용자 정의 공유 런타임 컨텍스트 객체.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'tool 이름을 키로 하는 tool별 컨텍스트 맵. 하나 이상의 tool이 contextSchema를 정의할 때 필수이며, 컨텍스트가 필요한 tool이 없으면 허용되지 않습니다.', }, { name: 'experimental_sandbox', type: 'Experimental_SandboxSession', isOptional: true, description: 'prepareStep, tool 설명 함수, tool 실행에 전달되는 experimental 샌드박스 환경. tool은 설명 함수 옵션과 실행 옵션에서 접근할 수 있습니다.', }, { name: 'experimental_download', type: '(requestedDownloads: Array<{ url: URL; isUrlSupportedByModel: boolean }>) => Promise<Array<null | { data: Uint8Array; mediaType?: string }>>', isOptional: true, description: '프롬프트에 URL이 나타날 때 URL을 가져오는 방식을 제어하는 커스텀 다운로드 함수. 기본적으로 모델이 주어진 미디어 타입의 URL을 지원하지 않으면 파일이 다운로드됩니다. 실험적 기능. 지원되는 경우 URL을 모델에 직접 전달하려면 null을, 또는 데이터와 미디어 타입이 있는 다운로드 콘텐츠를 반환하세요.', }, { name: 'include', type: '{ requestBody?: boolean; requestMessages?: boolean; responseBody?: boolean }', isOptional: true, description: 'step 결과에 요청 본문, 요청 메시지, 응답 본문의 포함 여부를 제어합니다. 기본적으로 메모리 사용을 줄이기 위해 요청 본문, 요청 메시지, 응답 본문이 제외됩니다. 데이터에 접근해야 할 때 requestBody, requestMessages, responseBody를 true로 설정하세요.', properties: [ { type: 'Object', parameters: [ { name: 'requestBody', type: 'boolean', isOptional: true, description: 'step 결과에 요청 본문을 포함할지 여부. 이미지나 파일을 보낼 때 요청 본문이 클 수 있습니다. 기본값: false.', }, { name: 'requestMessages', type: 'boolean', isOptional: true, description: 'step 결과에 요청 메시지를 포함할지 여부. 이미지나 파일을 보낼 때 요청 메시지가 클 수 있습니다. 기본값: false.', }, { name: 'responseBody', type: 'boolean', isOptional: true, description: 'step 결과에 응답 본문을 포함할지 여부. 기본값: false.', }, ], }, ], }, { name: 'repairToolCall', type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>', isOptional: true, description: '파싱에 실패한 tool 호출을 복구하려고 시도하는 함수. 복구된 tool 호출 또는 복구할 수 없으면 null을 반환하세요.', properties: [ { type: 'ToolCallRepairOptions', parameters: [ { name: 'instructions', type: 'Instructions | undefined', description: '모델에 제공된 지시문.', }, { name: 'system', type: 'Instructions | undefined', isOptional: true, description: '모델에 제공된 지시문. Deprecated: instructions를 대신 사용하세요.', }, { name: 'messages', type: 'ModelMessage[]', description: '현재 생성 단계의 메시지.', }, { name: 'toolCall', type: 'LanguageModelV4ToolCall', description: '파싱에 실패한 tool 호출.', }, { name: 'tools', type: 'TOOLS', description: '사용 가능한 tool들.', }, { name: 'inputSchema', type: '(options: { toolName: string }) => JSONSchema7', description: 'tool에 대한 JSON Schema를 반환하는 함수.', }, { name: 'error', type: 'NoSuchToolError | InvalidToolInputError', description: 'tool 호출을 파싱하는 동안 발생한 오류.', }, { name: 'abortSignal', type: 'AbortSignal', isOptional: true, description: 'tool 호출 복구를 취소하기 위한 선택적 신호.', }, ], }, ], }, { name: 'output', type: 'Output', isOptional: true, description: 'LLM 응답에서 구조화된 출력을 파싱하기 위한 명세.', properties: [ { type: 'Output', parameters: [ { name: 'Output.text()', type: 'Output', description: '텍스트 생성을 위한 출력 명세(기본값).', }, { name: 'Output.object()', type: 'Output', description: '스키마를 사용한 타입 지정 객체 생성을 위한 출력 명세. 모델이 텍스트 응답을 생성하면 스키마와 일치하는 객체를 반환합니다.', properties: [ { type: 'Options', parameters: [ { name: 'schema', type: 'Schema', description: '생성할 객체의 스키마.', }, { name: 'name', type: 'string', isOptional: true, description: '출력의 선택적 이름. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, { name: 'description', type: 'string', isOptional: true, description: '출력의 선택적 설명. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, ], }, ], }, { name: 'Output.array()', type: 'Output', description: '배열 생성을 위한 출력 명세. 모델이 텍스트 응답을 생성하면 요소 배열을 반환합니다.', properties: [ { type: 'Options', parameters: [ { name: 'element', type: 'Schema', description: '생성할 배열 요소의 스키마.', }, { name: 'minItems', type: 'number', isOptional: true, description: '선택적 최소 배열 요소 수. 음이 아닌 정수여야 합니다.', }, { name: 'maxItems', type: 'number', isOptional: true, description: '선택적 최대 배열 요소 수. 음이 아닌 정수여야 하며 minItems보다 크거나 같아야 합니다.', }, { name: 'name', type: 'string', isOptional: true, description: '출력의 선택적 이름. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, { name: 'description', type: 'string', isOptional: true, description: '출력의 선택적 설명. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, ], }, ], }, { name: 'Output.choice()', type: 'Output', description: '선택(choice) 생성을 위한 출력 명세. 모델이 텍스트 응답을 생성하면 선택 옵션 중 하나를 반환합니다.', properties: [ { type: 'Options', parameters: [ { name: 'options', type: 'Array', description: '사용 가능한 선택 항목.', }, { name: 'name', type: 'string', isOptional: true, description: '출력의 선택적 이름. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, { name: 'description', type: 'string', isOptional: true, description: '출력의 선택적 설명. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, ], }, ], }, { name: 'Output.json()', type: 'Output', description: '비구조화 JSON 생성을 위한 출력 명세. 모델이 텍스트 응답을 생성하면 JSON 객체를 반환합니다.', properties: [ { type: 'Options', parameters: [ { name: 'name', type: 'string', isOptional: true, description: '출력의 선택적 이름. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, { name: 'description', type: 'string', isOptional: true, description: '출력의 선택적 설명. 일부 프로바이더가 추가 LLM 지침으로 사용합니다.', }, ], }, ], }, ], }, ], }, { name: 'onStart', type: '(event: GenerateTextStartEvent) => PromiseLike | void', isOptional: true, description: 'generateText 작업이 시작될 때, LLM 호출이 이루어지기 전에 호출되는 콜백. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.', properties: [ { type: 'GenerateTextStartEvent', parameters: [ { name: 'provider', type: 'string', description: '프로바이더 식별자 (예: "openai", "anthropic").', }, { name: 'modelId', type: 'string', description: '특정 모델 식별자 (예: "gpt-6-astra").', }, { name: 'instructions', type: 'Instructions | undefined', description: '모델에 제공된 지시문.', }, { name: 'messages', type: 'Array', description: '이 생성의 메시지.', }, { name: 'tools', type: 'TOOLS | undefined', description: '이 생성에 사용 가능한 tool.', }, { name: 'toolChoice', type: 'ToolChoice | undefined', description: '이 생성의 tool 선택 전략.', }, { name: 'activeTools', type: 'ActiveTools', description: '모델이 호출할 수 있는 tool을 제한합니다.', }, { name: 'toolOrder', type: 'ToolOrder', description: 'tool을 프로바이더로 보내는 순서를 제어합니다.', }, { name: 'maxOutputTokens', type: 'number | undefined', description: '생성할 최대 토큰 수.', }, { name: 'temperature', type: 'number | undefined', description: '생성을 위한 샘플링 temperature.', }, { name: 'topP', type: 'number | undefined', description: 'Top-p (nucleus) 샘플링 파라미터.', }, { name: 'topK', type: 'number | undefined', description: 'Top-k 샘플링 파라미터.', }, { name: 'presencePenalty', type: 'number | undefined', description: '생성을 위한 presence penalty.', }, { name: 'frequencyPenalty', type: 'number | undefined', description: '생성을 위한 frequency penalty.', }, { name: 'stopSequences', type: 'string[] | undefined', description: '생성을 중단할 시퀀스.', }, { name: 'seed', type: 'number | undefined', description: '재현 가능한 생성을 위한 무작위 seed.', }, { name: 'maxRetries', type: 'number', description: '실패한 요청에 대한 최대 재시도 횟수.', }, { name: 'timeout', type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined', description: '생성을 위한 타임아웃 구성. 숫자(밀리초) 또는 totalMs, stepMs, chunkMs가 있는 객체일 수 있습니다.', }, { name: 'headers', type: 'Record<string, string | undefined> | undefined', description: '요청과 함께 보내는 추가 HTTP 헤더.', }, { name: 'providerOptions', type: 'ProviderOptions | undefined', description: '추가 프로바이더별 옵션.', }, { name: 'output', type: 'OUTPUT | undefined', description: '구성된 경우 구조화된 출력을 위한 출력 명세.', }, { name: 'abortSignal', type: 'AbortSignal | undefined', description: '작업 취소를 위한 abort signal.', }, { name: 'include', type: '{ requestBody?: boolean; requestMessages?: boolean; responseBody?: boolean } | undefined', description: 'step 결과에 포함할 데이터를 제어하는 설정.', }, { name: 'runtimeContext', type: 'CONTEXT', description: '생성 수명주기를 통해 흐르는 사용자 정의 공유 런타임 컨텍스트 객체.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'toolsContext를 통해 전달된, tool 이름을 키로 하는 tool별 컨텍스트 맵.', }, ], }, ], }, { name: 'onStepStart', type: '(event: GenerateTextStepStartEvent) => PromiseLike | void', isOptional: true, description: '단계(LLM 호출)가 시작될 때, 프로바이더가 호출되기 전에 호출되는 콜백. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.', properties: [ { type: 'GenerateTextStepStartEvent', parameters: [ { name: 'stepNumber', type: 'number', description: '현재 step의 0부터 시작하는 인덱스.', }, { name: 'provider', type: 'string', description: '프로바이더 식별자 (예: "openai", "anthropic").', }, { name: 'modelId', type: 'string', description: '특정 모델 식별자 (예: "gpt-6-astra").', }, { name: 'instructions', type: 'Instructions | undefined', description: '이 step에 대해 모델에 제공된 지시문.', }, { name: 'messages', type: 'Array', description: '이 step에 대해 모델로 보낼 메시지. 사용자 대상 ModelMessage 형식을 사용합니다. prepareStep에 의해 오버라이드될 수 있습니다. prepareStep이 messages 오버라이드를 반환하면 해당 메시지가 이후 단계로 전달됩니다.', }, { name: 'tools', type: 'TOOLS | undefined', description: '이 생성에 사용 가능한 tool.', }, { name: 'toolChoice', type: 'LanguageModelV4ToolChoice | undefined', description: '이 step의 tool 선택 구성.', }, { name: 'activeTools', type: 'ActiveTools', description: '이 step에서 사용 가능한 tool을 제한합니다.', }, { name: 'toolOrder', type: 'ToolOrder', description: '이 step에 대해 tool을 프로바이더로 보내는 순서를 제어합니다.', }, { name: 'steps', type: 'ReadonlyArray<StepResult>', description: '이전 단계의 결과 배열(첫 단계는 빈 배열).', }, { name: 'providerOptions', type: 'ProviderOptions | undefined', description: '이 step의 추가 프로바이더별 옵션.', }, { name: 'timeout', type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined', description: '생성을 위한 타임아웃 구성. 숫자(밀리초) 또는 totalMs, stepMs, chunkMs가 있는 객체일 수 있습니다.', }, { name: 'headers', type: 'Record<string, string | undefined> | undefined', description: '요청과 함께 보내는 추가 HTTP 헤더.', }, { name: 'stopWhen', type: 'StopCondition | Array<StopCondition> | undefined', description: '생성을 중단하기 위한 조건. 조건이 배열이면 그중 하나라도 충족되면 중단됩니다.', }, { name: 'output', type: 'OUTPUT | undefined', description: '구성된 경우 구조화된 출력을 위한 출력 명세.', }, { name: 'abortSignal', type: 'AbortSignal | undefined', description: '작업 취소를 위한 abort signal.', }, { name: 'include', type: '{ requestBody?: boolean; requestMessages?: boolean; responseBody?: boolean } | undefined', description: 'step 결과에 포함할 데이터를 제어하는 설정.', }, { name: 'runtimeContext', type: 'CONTEXT', description: '사용자 정의 공유 런타임 컨텍스트 객체. 단계 사이에 prepareStep에서 업데이트될 수 있습니다.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'tool별 컨텍스트 맵. 단계 사이에 prepareStep에서 업데이트될 수 있습니다.', }, ], }, ], }, { name: 'onLanguageModelCallStart', type: '(event: LanguageModelCallStartEvent) => PromiseLike | void', isOptional: true, description: '프로바이더 모델 호출이 시작되기 직전에 호출되는 콜백. onStepStart와 달리 이 콜백은 모델 작업에만 범위가 한정되며 이후의 클라이언트 측 tool 실행은 제외합니다. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.', properties: [ { type: 'LanguageModelCallStartEvent', parameters: [ { name: 'callId', type: 'string', description: '생성 호출의 고유 식별자.', }, { name: 'provider', type: 'string', description: '이 모델 호출의 프로바이더 식별자.', }, { name: 'modelId', type: 'string', description: '이 모델 호출의 특정 모델 식별자.', }, { name: 'instructions', type: 'Instructions | undefined', description: '모델로 보낼 지시문.', }, { name: 'messages', type: 'Array', description: '모델로 보낼 메시지.', }, { name: 'tools', type: 'ReadonlyArray<Record<string, unknown>> | undefined', description: '있을 경우 이 모델 호출을 위해 준비된 tool 정의.', }, ], }, ], }, { name: 'onLanguageModelCallEnd', type: '(event: LanguageModelCallEndEvent) => PromiseLike | void', isOptional: true, description: '모델 응답이 정규화되고 파싱된 후, 클라이언트 측 tool 실행이 시작되기 전에 호출되는 콜백. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.', properties: [ { type: 'LanguageModelCallEndEvent', parameters: [ { name: 'callId', type: 'string', description: '생성 호출의 고유 식별자.', }, { name: 'provider', type: 'string', description: '이 모델 호출의 프로바이더 식별자.', }, { name: 'modelId', type: 'string', description: '이 모델 호출에 대해 프로바이더가 반환한 모델 식별자.', }, { name: 'finishReason', type: 'FinishReason', description: '모델 호출이 완료된 통합 이유.', }, { name: 'usage', type: 'LanguageModelUsage', description: '모델 호출이 보고한 토큰 사용량.', }, { name: 'content', type: 'ReadonlyArray<ContentPart>', description: '모델 호출이 생성한 콘텐츠 part (텍스트, reasoning, 파일, tool 호출 등).', }, { name: 'responseId', type: 'string', description: '이 모델 호출에 대해 프로바이더가 반환한 응답 ID.', }, { name: 'providerMetadata', type: 'ProviderMetadata | undefined', description: '프로바이더가 반환할 때 이 모델 호출의 프로바이더별 메타데이터.', }, { name: 'performance', type: '{ responseTimeMs: number; effectiveOutputTokensPerSecond: number; outputTokensPerSecond: number | undefined; inputTokensPerSecond: number | undefined; effectiveTotalTokensPerSecond: number; timeToFirstOutputMs: number | undefined; timeBetweenOutputChunksMs?: OutputChunkTimingStats }', description: '모델 호출의 성능 지표.', properties: [ { type: 'LanguageModelCallPerformance', parameters: [ { name: 'responseTimeMs', type: 'number', description: '언어 모델 응답을 기다리는 데 소요된 밀리초 단위 시간.', }, { name: 'effectiveOutputTokensPerSecond', type: 'number', description: '전체 언어 모델 응답에 걸친 초당 유효 출력 토큰 수.', }, { name: 'outputTokensPerSecond', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받은 후 초당 출력 토큰 수. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'inputTokensPerSecond', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받기 전에 초당 처리된 입력 토큰 수. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'effectiveTotalTokensPerSecond', type: 'number', description: '전체 언어 모델 응답에 걸친 초당 유효 입력 및 출력 토큰 수.', }, { name: 'timeToFirstOutputMs', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받기까지의 밀리초 단위 시간. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'timeBetweenOutputChunksMs', type: 'OutputChunkTimingStats | undefined', description: '생성된 출력 chunk 사이의 간격에 대한 밀리초 단위 타이밍 통계. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, ], }, ], }, ], }, ], }, { name: 'onToolExecutionStart', type: '(event: ToolExecutionStartEvent) => PromiseLike | void', isOptional: true, description: "tool의 execute 함수가 실행되기 직전에 호출되는 콜백. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.", properties: [ { type: 'ToolExecutionStartEvent', parameters: [ { name: 'callId', type: 'string', description: '이 생성 호출의 고유 식별자로, 이벤트를 연관시키는 데 사용됩니다.', }, { name: 'toolCall', type: 'TypedToolCall', description: 'toolName, toolCallId, input, 메타데이터를 포함한 전체 tool 호출 객체.', }, { name: 'messages', type: 'Array', description: 'tool 호출을 포함한 응답을 시작하기 위해 언어 모델로 보낸 메시지. 시스템 프롬프트와 tool 호출을 포함한 어시스턴트 응답은 포함하지 않습니다.', }, { name: 'toolContext', type: 'InferToolContext<TOOLS[toolName]>', description: '실행될 tool 호출에 대한 tool별 컨텍스트 객체. 전체 tool 세트가 아니라 개별 tool의 컨텍스트 타입으로 좁혀집니다.', }, ], }, ], }, { name: 'onToolExecutionEnd', type: '(event: ToolExecutionEndEvent) => PromiseLike | void', isOptional: true, description: "tool의 execute 함수가 완료(또는 오류)된 직후에 호출되는 콜백. toolOutput 필드는 판별 유니언(discriminated union)입니다. toolOutput.type이 'tool-result'이면 output 필드에 tool 결과가 포함되고, toolOutput.type이 'tool-error'이면 error 필드에 오류가 포함됩니다. 이 콜백에서 발생한 오류는 조용히 잡히며 생성 흐름을 끊지 않습니다.", properties: [ { type: 'ToolExecutionEndEvent', parameters: [ { name: 'callId', type: 'string', description: '이 생성 호출의 고유 식별자로, 이벤트를 연관시키는 데 사용됩니다.', }, { name: 'toolCall', type: 'TypedToolCall', description: 'toolName, toolCallId, input, 메타데이터를 포함한 전체 tool 호출 객체.', }, { name: 'toolExecutionMs', type: 'number', description: 'tool 실행의 밀리초 단위 벽시계(wall-clock) 지속 시간.', }, { name: 'messages', type: 'Array', description: 'tool 호출을 포함한 응답을 시작하기 위해 언어 모델로 보낸 메시지. 시스템 프롬프트와 tool 호출을 포함한 어시스턴트 응답은 포함하지 않습니다.', }, { name: 'toolContext', type: 'InferToolContext<TOOLS[toolName]>', description: '방금 완료된 tool 호출에 대한 tool별 컨텍스트 객체. 전체 tool 세트가 아니라 개별 tool의 컨텍스트 타입으로 좁혀집니다.', }, { name: 'toolOutput', type: 'ToolOutput', description: "tool 실행 결과를 나타내는 판별 유니언. type이 'tool-result'이면 output 필드에 tool의 반환 값이 포함됩니다. type이 'tool-error'이면 error 필드에 오류가 포함됩니다.", }, ], }, ], }, { name: 'experimental_onToolCallStart', type: '(event: ToolExecutionStartEvent) => PromiseLike | void', isOptional: true, description: 'Deprecated. onToolExecutionStart를 대신 사용하세요. 이 별칭은 onToolExecutionStart가 제공되지 않을 때 폴백으로만 사용됩니다.', }, { name: 'experimental_onToolCallFinish', type: '(event: ToolExecutionEndEvent) => PromiseLike | void', isOptional: true, description: 'Deprecated. onToolExecutionEnd를 대신 사용하세요. 이 별칭은 onToolExecutionEnd가 제공되지 않을 때 폴백으로만 사용됩니다.', }, { name: 'onStepEnd', type: '(stepResult: StepResult) => Promise | void', isOptional: true, description: '단계가 끝날 때 호출되는 콜백. StepResult 객체를 받습니다.', properties: [ { type: 'StepResult', parameters: [ { name: 'stepNumber', type: 'number', description: '이 step의 0부터 시작하는 인덱스.', }, { name: 'model', type: '{ provider: string; modelId: string }', description: '이 step을 생성한 모델에 대한 정보.', }, { name: 'runtimeContext', type: 'CONTEXT', description: '생성을 통해 흐르는 사용자 정의 공유 런타임 컨텍스트 객체.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: '생성 단계의 tool별 컨텍스트 맵.', }, { name: 'content', type: 'Array<ContentPart>', description: '이 step에서 생성된 콘텐츠.', }, { name: 'text', type: 'string', description: '생성된 텍스트.', }, { name: 'reasoning', type: 'Array<ReasoningPart | ReasoningFilePart>', description: '생성 중 생성된 reasoning.', }, { name: 'reasoningText', type: 'string | undefined', description: '생성 중 생성된 reasoning 텍스트.', }, { name: 'files', type: 'Array', description: '생성 중 생성된 파일.', }, { name: 'sources', type: 'Array', description: '이 step에서 사용된 소스.', }, { name: 'toolCalls', type: 'Array<TypedToolCall>', description: '생성 중 이루어진 tool 호출.', }, { name: 'staticToolCalls', type: 'Array<StaticToolCall>', description: '이 step에서 이루어진 정적 tool 호출.', }, { name: 'dynamicToolCalls', type: 'Array', description: '이 step에서 이루어진 동적 tool 호출.', }, { name: 'toolResults', type: 'Array<TypedToolResult>', description: 'tool 호출의 결과.', }, { name: 'staticToolResults', type: 'Array<StaticToolResult>', description: '이 step에서 이루어진 정적 tool 결과.', }, { name: 'dynamicToolResults', type: 'Array', description: '이 step에서 이루어진 동적 tool 결과.', }, { name: 'finishReason', type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"', description: '생성이 완료된 통합 이유.', }, { name: 'rawFinishReason', type: 'string | undefined', description: '생성이 완료된 원시 이유 (프로바이더에서).', }, { name: 'usage', type: 'LanguageModelUsage', description: '생성된 텍스트의 토큰 사용량.', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '사용된 총 입력(프롬프트) 토큰 수.', }, { name: 'inputTokenDetails', type: 'LanguageModelInputTokenDetails', description: '입력(프롬프트) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelInputTokenDetails', parameters: [ { name: 'noCacheTokens', type: 'number | undefined', description: '사용된 캐시되지 않은 입력(프롬프트) 토큰 수.', }, { name: 'cacheReadTokens', type: 'number | undefined', description: '읽은 캐시된 입력(프롬프트) 토큰 수.', }, { name: 'cacheWriteTokens', type: 'number | undefined', description: '쓴 캐시된 입력(프롬프트) 토큰 수.', }, ], }, ], }, { name: 'outputTokens', type: 'number | undefined', description: '사용된 총 출력(완성) 토큰 수.', }, { name: 'outputTokenDetails', type: 'LanguageModelOutputTokenDetails', description: '출력(완성) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelOutputTokenDetails', parameters: [ { name: 'textTokens', type: 'number | undefined', description: '사용된 텍스트 토큰 수.', }, { name: 'reasoningTokens', type: 'number | undefined', description: '사용된 reasoning 토큰 수.', }, ], }, ], }, { name: 'totalTokens', type: 'number | undefined', description: '사용된 총 토큰 수.', }, { name: 'raw', type: 'object | undefined', isOptional: true, description: "프로바이더의 원시 사용량 정보. 프로바이더의 원래 사용량 정보로 추가 필드를 포함할 수 있습니다.", }, ], }, ], }, { name: 'performance', type: 'StepResultPerformance', description: '이 step의 타이밍 및 처리량 지표. generateText의 경우 스트리밍 전용 지표는 정의되지 않습니다.', properties: [ { type: 'StepResultPerformance', parameters: [ { name: 'effectiveOutputTokensPerSecond', type: 'number', description: '전체 언어 모델 응답에 걸친 초당 유효 출력 토큰 수.', }, { name: 'outputTokensPerSecond', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받은 후 초당 출력 토큰 수. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'inputTokensPerSecond', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받기 전에 초당 처리된 입력 토큰 수. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'effectiveTotalTokensPerSecond', type: 'number', description: '전체 언어 모델 응답에 걸친 초당 유효 입력 및 출력 토큰 수.', }, { name: 'stepTimeMs', type: 'number', description: '언어 모델 응답 시간과 tool 실행 시간을 포함한 이 step에 소요된 총 밀리초 단위 시간.', }, { name: 'responseTimeMs', type: 'number', description: '언어 모델 응답을 기다리는 데 소요된 밀리초 단위 시간.', }, { name: 'toolExecutionMs', type: 'Readonly<Record<string, number>>', description: '이 step에서 각 클라이언트 측 tool 호출을 실행하는 데 소요된 밀리초 단위 시간 (tool 호출 ID를 키로 함).', }, { name: 'timeToFirstOutputMs', type: 'number | undefined', description: '첫 번째 생성 출력 chunk를 받기까지의 밀리초 단위 시간. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, { name: 'timeBetweenOutputChunksMs', type: 'OutputChunkTimingStats | undefined', description: '생성된 출력 chunk 사이의 간격에 대한 밀리초 단위 타이밍 통계. generateText의 경우 응답이 스트리밍되지 않으므로 undefined입니다.', }, ], }, ], }, { name: 'warnings', type: 'CallWarning[] | undefined', description: '모델 프로바이더의 경고 (예: 지원되지 않는 설정).', }, { name: 'request', type: 'LanguageModelRequestMetadata', description: '추가 요청 정보.', properties: [ { type: 'LanguageModelRequestMetadata', parameters: [ { name: 'messages', type: 'Array', isOptional: true, description: '이 step에 대해 모델로 보낸 입력 메시지. requestMessages가 true로 설정되지 않으면 기본적으로 undefined입니다.', }, { name: 'body', type: 'unknown', isOptional: true, description: '프로바이더 API로 보낸 요청 HTTP 본문.', }, ], }, ], }, { name: 'response', type: 'LanguageModelResponseMetadata', description: '추가 응답 정보.', properties: [ { type: 'Response', parameters: [ { name: 'id', type: 'string', description: '응답 식별자. AI SDK는 프로바이더 응답의 ID를 사용 가능하면 사용하고, 그렇지 않으면 ID를 생성합니다.', }, { name: 'modelId', type: 'string', description: '응답을 생성하는 데 사용된 모델.', }, { name: 'timestamp', type: 'Date', description: '응답의 타임스탬프.', }, { name: 'headers', isOptional: true, type: 'Record<string, string>', description: '선택적 응답 헤더.', }, { name: 'messages', type: 'Array', description: '이 step 중 생성된 응답 메시지.', }, { name: 'body', isOptional: true, type: 'unknown', description: '응답 본문 (HTTP 요청을 사용하는 프로바이더에서만 사용 가능).', }, ], }, ], }, { name: 'providerMetadata', type: 'ProviderMetadata | undefined', isOptional: true, description: '추가 프로바이더별 메타데이터. 프로바이더에서 AI SDK로 전달되며 프로바이더에 완전히 캡슐화될 수 있는 프로바이더별 결과를 가능하게 합니다.', }, { name: 'responseMessages', type: 'Array', description: '호출 중 생성된 누적 응답 메시지.', }, ], }, ], }, { name: 'onStepFinish', type: 'GenerateTextOnStepFinishCallback', isOptional: true, description: 'Deprecated. onStepEnd를 대신 사용하세요. 이 별칭은 onStepEnd가 제공되지 않을 때 폴백으로만 사용됩니다.', }, { name: 'onEnd', type: '(event: GenerateTextEndEvent) => PromiseLike | void', isOptional: true, description: '전체 생성이 완료될 때(모든 step이 끝났을 때) 호출되는 콜백. 이벤트에는 직접적인 performance를 제외한 최종 step 결과 속성과 모든 step의 집계 데이터가 포함됩니다. step별 성능 지표에는 event.steps를 사용하세요.', properties: [ { type: 'GenerateTextEndEvent', parameters: [ { name: 'stepNumber', type: 'number', description: '최종 step의 0부터 시작하는 인덱스.', }, { name: 'model', type: '{ provider: string; modelId: string }', description: '최종 step을 생성한 모델에 대한 정보.', }, { name: 'finishReason', type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"', description: '생성이 완료된 통합 이유.', }, { name: 'rawFinishReason', type: 'string | undefined', description: '생성이 완료된 원시 이유 (프로바이더에서).', }, { name: 'usage', type: 'LanguageModelUsage', description: '최종 step의 토큰 사용량 (집계가 아님).', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '사용된 총 입력(프롬프트) 토큰 수.', }, { name: 'inputTokenDetails', type: 'LanguageModelInputTokenDetails', description: '입력(프롬프트) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelInputTokenDetails', parameters: [ { name: 'noCacheTokens', type: 'number | undefined', description: '사용된 캐시되지 않은 입력(프롬프트) 토큰 수.', }, { name: 'cacheReadTokens', type: 'number | undefined', description: '읽은 캐시된 입력(프롬프트) 토큰 수.', }, { name: 'cacheWriteTokens', type: 'number | undefined', description: '쓴 캐시된 입력(프롬프트) 토큰 수.', }, ], }, ], }, { name: 'outputTokens', type: 'number | undefined', description: '사용된 총 출력(완성) 토큰 수.', }, { name: 'outputTokenDetails', type: 'LanguageModelOutputTokenDetails', description: '출력(완성) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelOutputTokenDetails', parameters: [ { name: 'textTokens', type: 'number | undefined', description: '사용된 텍스트 토큰 수.', }, { name: 'reasoningTokens', type: 'number | undefined', description: '사용된 reasoning 토큰 수.', }, ], }, ], }, { name: 'totalTokens', type: 'number | undefined', description: '사용된 총 토큰 수.', }, { name: 'raw', type: 'object | undefined', isOptional: true, description: "프로바이더의 원시 사용량 정보. 프로바이더의 원래 사용량 정보로 추가 필드를 포함할 수 있습니다.", }, ], }, ], }, { name: 'totalUsage', type: 'LanguageModelUsage', description: '모든 step에 걸친 집계 토큰 사용량. 각 개별 step 사용량의 합입니다.', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '모든 step에 걸쳐 사용된 총 입력(프롬프트) 토큰 수.', }, { name: 'outputTokens', type: 'number | undefined', description: '모든 step에 걸쳐 사용된 총 출력(완성) 토큰 수.', }, { name: 'totalTokens', type: 'number | undefined', description: '모든 step에 걸쳐 사용된 총 토큰 수.', }, ], }, ], }, { name: 'content', type: 'Array<ContentPart>', description: '모든 step에서 생성된 콘텐츠.', }, { name: 'providerMetadata', type: 'ProviderMetadata | undefined', description: '최종 step의 추가 프로바이더별 메타데이터.', }, { name: 'text', type: 'string', description: '생성된 전체 텍스트.', }, { name: 'reasoningText', type: 'string | undefined', description: '모델의 reasoning 텍스트 (일부 모델에서만 사용 가능).', }, { name: 'reasoning', type: 'Array', description: '모델의 reasoning 세부 정보 (일부 모델에서만 사용 가능).', properties: [ { type: 'ReasoningDetail', parameters: [ { name: 'type', type: "'text'", description: 'reasoning 세부 정보의 타입.', }, { name: 'text', type: 'string', description: '텍스트 내용 ("text" 타입에만 해당).', }, { name: 'signature', type: 'string', isOptional: true, description: '선택적 시그니처 ("text" 타입에만 해당).', }, ], }, { type: 'ReasoningDetail', parameters: [ { name: 'type', type: "'redacted'", description: 'reasoning 세부 정보의 타입.', }, { name: 'data', type: 'string', description: '수정(redacted) 데이터 내용 ("redacted" 타입에만 해당).', }, ], }, ], }, { name: 'sources', type: 'Array', description: '최종 step에서 사용된 소스.', properties: [ { type: 'Source', parameters: [ { name: 'sourceType', type: "'url'", description: 'URL 소스. 웹 검색 RAG 모델이 반환합니다.', }, { name: 'id', type: 'string', description: '소스의 ID.', }, { name: 'url', type: 'string', description: '소스의 URL.', }, { name: 'title', type: 'string', isOptional: true, description: '소스의 제목.', }, { name: 'providerMetadata', type: 'SharedV2ProviderMetadata', isOptional: true, description: '소스에 대한 추가 프로바이더 메타데이터.', }, ], }, ], }, { name: 'files', type: 'Array', description: '모든 step에서 생성된 파일.', properties: [ { type: 'GeneratedFile', parameters: [ { name: 'base64', type: 'string', description: 'base64 인코딩 문자열로 된 파일.', }, { name: 'uint8Array', type: 'Uint8Array', description: 'Uint8Array로 된 파일.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, ], }, { name: 'toolCalls', type: 'Array<TypedToolCall>', description: '생성 중 이루어진 tool 호출.', }, { name: 'staticToolCalls', type: 'Array<StaticToolCall>', description: '최종 step에서 이루어진 정적 tool 호출.', }, { name: 'dynamicToolCalls', type: 'Array', description: '최종 step에서 이루어진 동적 tool 호출.', }, { name: 'toolResults', type: 'Array<TypedToolResult>', description: 'tool 호출의 결과.', }, { name: 'staticToolResults', type: 'Array<StaticToolResult>', description: '최종 step에서 이루어진 정적 tool 결과.', }, { name: 'dynamicToolResults', type: 'Array', description: '최종 step에서 이루어진 동적 tool 결과.', }, { name: 'warnings', type: 'CallWarning[] | undefined', description: '모든 step에서 모델 프로바이더의 경고 (예: 지원되지 않는 설정).', }, { name: 'request', type: 'LanguageModelRequestMetadata', description: '최종 step의 추가 요청 정보.', properties: [ { type: 'LanguageModelRequestMetadata', parameters: [ { name: 'messages', type: 'Array', isOptional: true, description: '이 step에 대해 모델로 보낸 입력 메시지. requestMessages가 true로 설정되지 않으면 기본적으로 undefined입니다.', }, { name: 'body', type: 'unknown', isOptional: true, description: '프로바이더 API로 보낸 요청 HTTP 본문.', }, ], }, ], }, { name: 'response', type: 'LanguageModelResponseMetadata', description: '최종 step의 추가 응답 정보.', properties: [ { type: 'Response', parameters: [ { name: 'id', type: 'string', description: '응답 식별자. AI SDK는 프로바이더 응답의 ID를 사용 가능하면 사용하고, 그렇지 않으면 ID를 생성합니다.', }, { name: 'modelId', type: 'string', description: '응답을 생성하는 데 사용된 모델. AI SDK는 프로바이더 응답의 응답 모델을 사용 가능하면 사용하고, 그렇지 않으면 함수 호출의 모델을 사용합니다.', }, { name: 'timestamp', type: 'Date', description: '응답의 타임스탬프. AI SDK는 프로바이더 응답의 응답 타임스탬프를 사용 가능하면 사용하고, 그렇지 않으면 타임스탬프를 생성합니다.', }, { name: 'headers', isOptional: true, type: 'Record<string, string>', description: '선택적 응답 헤더.', }, { name: 'body', isOptional: true, type: 'unknown', description: '응답 본문 (HTTP 요청을 사용하는 프로바이더에서만 사용 가능).', }, { name: 'messages', type: 'Array', description: '이 step 중 생성된 응답 메시지. 잠재적으로 tool 호출을 포함하는 어시스턴트 메시지로 구성됩니다. 이 step에 tool 결과가 있으면 사용 가능한 tool 결과가 있는 추가 tool 메시지가 있습니다. execute 함수가 없는 tool이 있으면 tool 결과에 포함되지 않으므로 별도로 추가해야 합니다.', }, ], }, ], }, { name: 'steps', type: 'Array', description: '모든 step에 대한 응답 정보. 중간 step에 대한 정보(예: tool 호출 또는 응답 헤더)를 얻는 데 사용할 수 있습니다.', }, { name: 'finalStep', type: 'StepResult', description: '최종 step. steps.at(-1)의 단축입니다.', }, { name: 'responseMessages', type: 'Array', description: '호출 중 생성된 누적 응답 메시지.', }, { name: 'runtimeContext', type: 'CONTEXT', description: 'Deprecated. finalStep.runtimeContext를 대신 사용하세요. 사용자 정의 공유 런타임 컨텍스트 객체의 최종 상태. 생성 수명주기 동안 prepareStep을 통해 이루어진 수정을 반영합니다.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: 'Deprecated. finalStep.toolsContext를 대신 사용하세요. toolsContext를 통해 전달된 tool별 컨텍스트 맵의 최종 상태.', }, ], }, ], }, { name: 'onFinish', type: '(event: GenerateTextEndEvent) => PromiseLike | void', isOptional: true, description: 'Deprecated alias for onEnd.', }, ]} />

반환 값 (Returns)

<PropertiesTable content={[ { name: 'content', type: 'Array<ContentPart>', description: '모든 step에서 생성된 콘텐츠.', }, { name: 'text', type: 'string', description: '최종 step에서 생성된 모든 텍스트 part의 연결(concatenation). 최종 step에 텍스트 part가 없으면 빈 문자열입니다. 그 경우를 구별하려면 finalStep.content를 검사하세요.', }, { name: 'reasoning', type: 'Array<ReasoningOutput | ReasoningFileOutput>', description: 'Deprecated. finalStep.reasoning을 대신 사용하세요. 모델이 최종 step에서 생성한 전체 reasoning.', properties: [ { type: 'ReasoningOutput', parameters: [ { name: 'type', type: "'reasoning'", description: '메시지 part의 타입.', }, { name: 'text', type: 'string', description: 'reasoning 텍스트.', }, { name: 'providerMetadata', type: 'SharedV2ProviderMetadata', isOptional: true, description: '추가 프로바이더 메타데이터.', }, ], }, { type: 'ReasoningFileOutput', parameters: [ { name: 'type', type: "'reasoning-file'", description: '메시지 part의 타입.', }, { name: 'file', type: 'GeneratedFile', description: '생성된 파일.', }, { name: 'providerMetadata', type: 'SharedV2ProviderMetadata', isOptional: true, description: '추가 프로바이더 메타데이터.', }, ], }, ], }, { name: 'reasoningText', type: 'string | undefined', description: 'Deprecated. finalStep.reasoningText를 대신 사용하세요. 모델이 최종 step에서 생성한 reasoning 텍스트. 모델이 텍스트만 생성했다면 undefined일 수 있습니다.', }, { name: 'sources', type: 'Array', description: '응답을 생성하기 위한 입력으로 사용된 소스. 멀티스텝 생성에서는 모든 step에서 소스가 누적됩니다.', properties: [ { type: 'Source', parameters: [ { name: 'sourceType', type: "'url'", description: 'URL 소스. 웹 검색 RAG 모델이 반환합니다.', }, { name: 'id', type: 'string', description: '소스의 ID.', }, { name: 'url', type: 'string', description: '소스의 URL.', }, { name: 'title', type: 'string', isOptional: true, description: '소스의 제목.', }, { name: 'providerMetadata', type: 'SharedV2ProviderMetadata', isOptional: true, description: '소스에 대한 추가 프로바이더 메타데이터.', }, ], }, ], }, { name: 'files', type: 'Array', description: '모든 step에서 생성된 파일.', properties: [ { type: 'GeneratedFile', parameters: [ { name: 'base64', type: 'string', description: 'base64 인코딩 문자열로 된 파일.', }, { name: 'uint8Array', type: 'Uint8Array', description: 'Uint8Array로 된 파일.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, ], }, { name: 'toolCalls', type: 'ToolCallArray', description: '모든 step에서 이루어진 tool 호출.', }, { name: 'toolResults', type: 'ToolResultArray', description: '모든 step의 tool 호출 결과.', }, { name: 'staticToolCalls', type: 'Array<StaticToolCall>', description: '모든 step에서 실행된 정적 tool 호출.', }, { name: 'dynamicToolCalls', type: 'Array', description: '모든 step에서 실행된 동적 tool 호출.', }, { name: 'staticToolResults', type: 'Array<StaticToolResult>', description: '모든 step에서 생성된 정적 tool 결과.', }, { name: 'dynamicToolResults', type: 'Array', description: '모든 step에서 생성된 동적 tool 결과.', }, { name: 'finishReason', type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'", description: '모델이 텍스트 생성을 완료한 이유.', }, { name: 'rawFinishReason', type: 'string | undefined', description: '생성이 완료된 원시 이유 (프로바이더에서).', }, { name: 'usage', type: 'LanguageModelUsage', description: '모든 step의 총 토큰 사용량. 여러 step이 있을 때 usage는 모든 step 사용량의 합입니다.', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '사용된 총 입력(프롬프트) 토큰 수.', }, { name: 'inputTokenDetails', type: 'LanguageModelInputTokenDetails', description: '입력(프롬프트) 토큰에 대한 상세 정보. 캐시된 토큰과 캐시되지 않은 토큰도 참고하세요.', properties: [ { type: 'LanguageModelInputTokenDetails', parameters: [ { name: 'noCacheTokens', type: 'number | undefined', description: '사용된 캐시되지 않은 입력(프롬프트) 토큰 수.', }, { name: 'cacheReadTokens', type: 'number | undefined', description: '읽은 캐시된 입력(프롬프트) 토큰 수.', }, { name: 'cacheWriteTokens', type: 'number | undefined', description: '쓴 캐시된 입력(프롬프트) 토큰 수.', }, ], }, ], }, { name: 'outputTokens', type: 'number | undefined', description: '사용된 총 출력(완성) 토큰 수.', }, { name: 'outputTokenDetails', type: 'LanguageModelOutputTokenDetails', description: '출력(완성) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelOutputTokenDetails', parameters: [ { name: 'textTokens', type: 'number | undefined', description: '사용된 텍스트 토큰 수.', }, { name: 'reasoningTokens', type: 'number | undefined', description: '사용된 reasoning 토큰 수.', }, ], }, ], }, { name: 'totalTokens', type: 'number | undefined', description: '사용된 총 토큰 수.', }, { name: 'raw', type: 'object | undefined', isOptional: true, description: "프로바이더의 원시 사용량 정보. 프로바이더의 원래 사용량 정보로 추가 필드를 포함할 수 있습니다.", }, ], }, ], }, { name: 'totalUsage', type: 'LanguageModelUsage', description: 'Deprecated. usage를 대신 사용하세요. 모든 step의 총 토큰 사용량. 여러 step이 있을 때 usage는 모든 step 사용량의 합입니다.', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '사용된 입력(프롬프트) 토큰 수.', }, { name: 'outputTokens', type: 'number | undefined', description: '사용된 출력(완성) 토큰 수.', }, { name: 'totalTokens', type: 'number | undefined', description: '프로바이더가 보고한 총 토큰 수. 이 숫자는 inputTokens와 outputTokens의 합과 다를 수 있으며, 예를 들어 reasoning 토큰이나 기타 오버헤드를 포함할 수 있습니다.', }, ], }, ], }, { name: 'request', type: 'LanguageModelRequestMetadata', isOptional: true, description: 'Deprecated. finalStep.request를 대신 사용하세요. 최종 step의 요청 메타데이터.', properties: [ { type: 'LanguageModelRequestMetadata', parameters: [ { name: 'messages', type: 'Array', isOptional: true, description: '이 step에 대해 모델로 보낸 입력 메시지. requestMessages가 true로 설정되지 않으면 기본적으로 undefined입니다.', }, { name: 'body', type: 'unknown', isOptional: true, description: '프로바이더 API로 보낸 요청 HTTP 본문.', }, ], }, ], }, { name: 'response', type: 'LanguageModelResponseMetadata', isOptional: true, description: 'Deprecated. finalStep.response를 대신 사용하세요. 최종 step의 응답 메타데이터.', properties: [ { type: 'LanguageModelResponseMetadata', parameters: [ { name: 'id', type: 'string', description: '응답 식별자. AI SDK는 프로바이더 응답의 ID를 사용 가능하면 사용하고, 그렇지 않으면 ID를 생성합니다.', }, { name: 'modelId', type: 'string', description: '응답을 생성하는 데 사용된 모델. AI SDK는 프로바이더 응답의 응답 모델을 사용 가능하면 사용하고, 그렇지 않으면 함수 호출의 모델을 사용합니다.', }, { name: 'timestamp', type: 'Date', description: '응답의 타임스탬프. AI SDK는 프로바이더 응답의 응답 타임스탬프를 사용 가능하면 사용하고, 그렇지 않으면 타임스탬프를 생성합니다.', }, { name: 'headers', isOptional: true, type: 'Record<string, string>', description: '선택적 응답 헤더.', }, { name: 'body', isOptional: true, type: 'unknown', description: '선택적 응답 본문.', }, { name: 'messages', type: 'Array', description: '최종 step 중 생성된 응답 메시지. 잠재적으로 tool 호출을 포함하는 어시스턴트 메시지로 구성됩니다. 최종 step에 tool 결과가 있으면 사용 가능한 tool 결과가 있는 추가 tool 메시지가 있습니다. execute 함수가 없는 tool이 있으면 tool 결과에 포함되지 않으므로 별도로 추가해야 합니다.', }, ], }, ], }, { name: 'warnings', type: 'Warning[] | undefined', description: '모든 step에서 모델 프로바이더의 경고 (예: 지원되지 않는 설정).', }, { name: 'responseMessages', type: 'Array', description: '호출 중 생성된 모든 step의 누적 응답 메시지.', }, { name: 'providerMetadata', type: 'ProviderMetadata | undefined', description: 'Deprecated. finalStep.providerMetadata를 대신 사용하세요. 최종 step에 대한 프로바이더의 선택적 메타데이터. 바깥쪽 키는 프로바이더 이름입니다. 안쪽 값은 메타데이터입니다. 세부 사항은 프로바이더에 따라 다릅니다.', }, { name: 'output', type: 'InferCompleteOutput', description: 'output 명세에 따라 생성된 출력. 이 속성에 접근하면 출력이 없을 때(예: 최종 step이 stop 이유로 끝나지 않을 때) NoOutputGeneratedError가 발생합니다.', }, { name: 'steps', type: 'Array<StepResult>', description: '모든 step에 대한 응답 정보. 중간 step에 대한 정보(예: tool 호출 또는 응답 헤더)를 얻는 데 사용할 수 있습니다.', properties: [ { type: 'StepResult', parameters: [ { name: 'stepNumber', type: 'number', description: '이 step의 0부터 시작하는 인덱스.', }, { name: 'model', type: '{ provider: string; modelId: string }', description: '이 step을 생성한 모델에 대한 정보.', }, { name: 'runtimeContext', type: 'CONTEXT', description: '생성을 통해 흐르는 사용자 정의 공유 런타임 컨텍스트 객체.', }, { name: 'toolsContext', type: 'InferToolSetContext', description: '최종 생성 step의 tool별 컨텍스트 맵.', }, { name: 'content', type: 'Array<ContentPart>', description: '최종 step에서 생성된 콘텐츠.', }, { name: 'text', type: 'string', description: '이 step에서 생성된 모든 텍스트 part의 연결. step에 텍스트 part가 없으면 빈 문자열입니다.', }, { name: 'reasoning', type: 'Array<ReasoningPart | ReasoningFilePart>', description: '생성 중 생성된 reasoning.', properties: [ { type: 'ReasoningPart', parameters: [ { name: 'type', type: "'reasoning'", description: '메시지 part의 타입.', }, { name: 'text', type: 'string', description: 'reasoning 텍스트.', }, ], }, { type: 'ReasoningFilePart', parameters: [ { name: 'type', type: "'reasoning-file'", description: '메시지 part의 타입.', }, { name: 'data', type: 'string | Uint8Array | Buffer | ArrayBuffer | URL', description: '파일 데이터. 문자열은 base64 인코딩 콘텐츠, base64 데이터 URL 또는 http(s) URL입니다.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, ], }, { name: 'reasoningText', type: 'string | undefined', description: '생성 중 생성된 reasoning 텍스트.', }, { name: 'files', type: 'Array', description: '생성 중 생성된 파일.', properties: [ { type: 'GeneratedFile', parameters: [ { name: 'base64', type: 'string', description: 'base64 인코딩 문자열로 된 파일.', }, { name: 'uint8Array', type: 'Uint8Array', description: 'Uint8Array로 된 파일.', }, { name: 'mediaType', type: 'string', description: '파일의 IANA 미디어 타입.', }, ], }, ], }, { name: 'sources', type: 'Array', description: '이 step에서 사용된 소스.', properties: [ { type: 'Source', parameters: [ { name: 'sourceType', type: "'url'", description: 'URL 소스. 웹 검색 RAG 모델이 반환합니다.', }, { name: 'id', type: 'string', description: '소스의 ID.', }, { name: 'url', type: 'string', description: '소스의 URL.', }, { name: 'title', type: 'string', isOptional: true, description: '소스의 제목.', }, { name: 'providerMetadata', type: 'SharedV2ProviderMetadata', isOptional: true, description: '소스에 대한 추가 프로바이더 메타데이터.', }, ], }, ], }, { name: 'toolCalls', type: 'ToolCallArray', description: '생성 중 이루어진 tool 호출.', }, { name: 'toolResults', type: 'ToolResultArray', description: 'tool 호출의 결과.', }, { name: 'finishReason', type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'", description: '생성이 완료된 이유.', }, { name: 'rawFinishReason', type: 'string | undefined', description: '생성이 완료된 원시 이유 (프로바이더에서).', }, { name: 'usage', type: 'LanguageModelUsage', description: '생성된 텍스트의 토큰 사용량.', properties: [ { type: 'LanguageModelUsage', parameters: [ { name: 'inputTokens', type: 'number | undefined', description: '사용된 총 입력(프롬프트) 토큰 수.', }, { name: 'inputTokenDetails', type: 'LanguageModelInputTokenDetails', description: '입력(프롬프트) 토큰에 대한 상세 정보. 캐시된 토큰과 캐시되지 않은 토큰도 참고하세요.', properties: [ { type: 'LanguageModelInputTokenDetails', parameters: [ { name: 'noCacheTokens', type: 'number | undefined', description: '사용된 캐시되지 않은 입력(프롬프트) 토큰 수.', }, { name: 'cacheReadTokens', type: 'number | undefined', description: '읽은 캐시된 입력(프롬프트) 토큰 수.', }, { name: 'cacheWriteTokens', type: 'number | undefined', description: '쓴 캐시된 입력(프롬프트) 토큰 수.', }, ], }, ], }, { name: 'outputTokens', type: 'number | undefined', description: '사용된 총 출력(완성) 토큰 수.', }, { name: 'outputTokenDetails', type: 'LanguageModelOutputTokenDetails', description: '출력(완성) 토큰에 대한 상세 정보.', properties: [ { type: 'LanguageModelOutputTokenDetails', parameters: [ { name: 'textTokens', type: 'number | undefined', description: '사용된 텍스트 토큰 수.', }, { name: 'reasoningTokens', type: 'number | undefined', description: '사용된 reasoning 토큰 수.', }, ], }, ], }, { name: 'totalTokens', type: 'number | undefined', description: '사용된 총 토큰 수.', }, { name: 'raw', type: 'object | undefined', isOptional: true, description: "프로바이더의 원시 사용량 정보. 프로바이더의 원래 사용량 정보로 추가 필드를 포함할 수 있습니다.", }, ], }, ], }, { name: 'warnings', type: 'Warning[] | undefined', description: '모델 프로바이더의 경고 (예: 지원되지 않는 설정).', }, { name: 'request', type: 'LanguageModelRequestMetadata', description: '추가 요청 정보.', properties: [ { type: 'LanguageModelRequestMetadata', parameters: [ { name: 'messages', type: 'Array', isOptional: true, description: '이 step에 대해 모델로 보낸 입력 메시지. requestMessages가 true로 설정되지 않으면 기본적으로 undefined입니다.', }, { name: 'body', type: 'unknown', isOptional: true, description: '프로바이더 API로 보낸 요청 HTTP 본문.', }, ], }, ], }, { name: 'response', type: 'LanguageModelResponseMetadata', description: '추가 응답 정보.', properties: [ { type: 'LanguageModelResponseMetadata', parameters: [ { name: 'id', type: 'string', description: '응답 식별자. AI SDK는 프로바이더 응답의 ID를 사용 가능하면 사용하고, 그렇지 않으면 ID를 생성합니다.', }, { name: 'modelId', type: 'string', description: '응답을 생성하는 데 사용된 모델. AI SDK는 프로바이더 응답의 응답 모델을 사용 가능하면 사용하고, 그렇지 않으면 함수 호출의 모델을 사용합니다.', }, { name: 'timestamp', type: 'Date', description: '응답의 타임스탬프. AI SDK는 프로바이더 응답의 응답 타임스탬프를 사용 가능하면 사용하고, 그렇지 않으면 타임스탬프를 생성합니다.', }, { name: 'headers', isOptional: true, type: 'Record<string, string>', description: '선택적 응답 헤더.', }, { name: 'body', isOptional: true, type: 'unknown', description: '응답 본문 (HTTP 요청을 사용하는 프로바이더에서만 사용 가능).', }, { name: 'messages', type: 'Array', description: '이 step 중 생성된 응답 메시지. 응답 메시지는 어시스턴트 메시지 또는 tool 메시지일 수 있습니다. 생성된 id를 포함합니다.', }, ], }, ], }, { name: 'providerMetadata', type: 'ProviderMetadata | undefined', description: '추가 프로바이더별 메타데이터. 프로바이더에서 AI SDK로 전달되며 프로바이더에 완전히 캡슐화될 수 있는 프로바이더별 결과를 가능하게 합니다.', }, ], }, ], }, { name: 'finalStep', type: 'StepResult', description: '최종 step. steps.at(-1)의 단축입니다.', }, ]} />

타입 (Types)

ActiveTools

type ActiveTools<TOOLS extends ToolSet> =
  | ReadonlyArray<keyof TOOLS & string>
  | undefined;

생성 step을 나열된 tool 이름으로 제한합니다. undefined는 tool 제한이 적용되지 않음을 의미합니다.

더 알아보기 (Learn more)

예제 (Examples)

<ExampleLinks examples={[ { title: 'Next.js에서 언어 모델을 사용해 텍스트를 생성하는 법 배우기', link: '/examples/next-app/basics/generating-text', }, { title: 'Next.js에서 언어 모델을 사용해 채팅 완성을 생성하는 법 배우기', link: '/examples/next-app/basics/generating-text', }, { title: 'Next.js에서 언어 모델을 사용해 tool을 호출하는 법 배우기', link: '/examples/next-app/tools/call-tool', }, { title: 'Next.js에서 언어 모델을 사용해 React 컴포넌트를 tool 호출로 렌더링하는 법 배우기', link: '/examples/next-app/tools/render-interface-during-tool-call', }, { title: 'Node.js에서 언어 모델을 사용해 텍스트를 생성하는 법 배우기', link: '/examples/node/generating-text/generate-text', }, { title: 'Node.js에서 언어 모델을 사용해 채팅 완성을 생성하는 법 배우기', link: '/examples/node/generating-text/generate-text-with-chat-prompt', }, ]} />

내비게이션 (Navigation)

Full Sitemap