Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openai-compatible/llms.txt
Use this file to discover all available pages before exploring further.
MapsFinishReason normalizes the raw finish_reason string returned by OpenAI-compatible APIs into the portable AiSdk\FinishReason enum used across the SDK. It is called by both ChatResponseParser (for non-streaming responses) and ChatStreamParser (for the final chunk of a streaming response) to ensure a consistent finish-reason value regardless of which provider issued the response.
Namespace
Methods
map()
finish_reason string from an API response and returns the corresponding AiSdk\FinishReason enum case. The input is nullable because some streaming chunks carry a null finish reason before the final chunk arrives; those are treated identically to 'stop'.
The raw
finish_reason value from the API response. May be null for intermediate streaming chunks or when the field is absent from the payload.AiSdk\FinishReason — one of the portable enum cases described in the mapping table below.
Finish reason mapping
Input finish_reason | FinishReason value | Notes |
|---|---|---|
'stop' | FinishReason::Stop | Normal end of generation |
'end_turn' | FinishReason::Stop | Anthropic-style alias for stop |
'length' | FinishReason::Length | Max output tokens reached |
'max_tokens' | FinishReason::Length | Provider alias for length |
'tool_calls' | FinishReason::ToolCalls | Model called one or more tools |
'function_call' | FinishReason::ToolCalls | Legacy function-call alias |
'content_filter' | FinishReason::ContentFilter | Output blocked by safety policy |
null | FinishReason::Stop | Treated as a normal stop |
| any other value | FinishReason::Unknown | Forward-compatible fallback |