Don't expose token usage in streamed responses #6501
Answered
by
patelvivekdev
Edwin-Luijten
asked this question in
Help
-
Is there a way to hide the token usage from the response stream? |
Beta Was this translation helpful? Give feedback.
Answered by
patelvivekdev
May 29, 2025
Replies: 1 comment 1 reply
-
You can pass import { convertToCoreMessages, streamText, UIMessage } from "ai";
import { google } from "@ai-sdk/google";
export const maxDuration = 60;
export async function POST(req: Request) {
const {
messages,
}: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: google("gemini-2.0-flash"),
system: "You are a helpful assistant.",
messages: convertToCoreMessages(messages)
});
return result.toDataStreamResponse({ sendUsage: false });
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Edwin-Luijten
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass
sendUsage
tofalse
https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#merge-into-data-stream.data-stream-options.send-usage