@@ -59,6 +59,7 @@ if (!process.env.OPENAI_API_KEY) {
5959}
6060const CHAT_LOG_PREFIX = '[chat:dev]'
6161const isDevLogging = process . env . NODE_ENV === 'development'
62+ const isAiTelemetryEnabled = process . env . CHAT_ENABLE_AI_TELEMETRY !== 'false'
6263const MAX_LOG_STRING_LENGTH = 500
6364const HASH_DIGEST_LENGTH = 12
6465
@@ -1268,7 +1269,7 @@ export async function POST(
12681269 const result = streamText ( {
12691270 model,
12701271 maxOutputTokens,
1271- experimental_telemetry : { isEnabled : true } ,
1272+ experimental_telemetry : { isEnabled : isAiTelemetryEnabled } ,
12721273 providerOptions : {
12731274 openai : {
12741275 ...( selectedModelConfig . supportsReasoning && {
@@ -1691,6 +1692,20 @@ export async function POST(
16911692
16921693 return result . toUIMessageStreamResponse ( {
16931694 sendReasoning : true ,
1695+ onError : ( error ) => {
1696+ const serializedError = serializeStreamError ( error )
1697+ const classification = classifyStreamError ( serializedError )
1698+
1699+ console . error ( 'Error while streaming UI message response:' , {
1700+ requestId,
1701+ error : serializedError ,
1702+ classification : classification . classification ,
1703+ retryable : classification . retryable ,
1704+ suggestedAction : classification . suggestedAction ,
1705+ } )
1706+
1707+ return 'An error occurred while processing the request.'
1708+ } ,
16941709 messageMetadata : ( { part } ) => {
16951710 if ( part . type !== 'finish' ) {
16961711 return undefined
0 commit comments