Skip to content

Responses API Streaming: token too long error #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alecrubin opened this issue Apr 9, 2025 · 1 comment · May be fixed by #373
Open

Responses API Streaming: token too long error #368

alecrubin opened this issue Apr 9, 2025 · 1 comment · May be fixed by #373

Comments

@alecrubin
Copy link

alecrubin commented Apr 9, 2025

When using the client.Responses.NewStreaming() method, I have noticed intermittent errors with the bufio.Scanner, resulting in this error: bufio.Scanner: token too long.

@mrene
Copy link

mrene commented Apr 15, 2025

We've also seen this issue, it happens when an SSE event is larger than bufio.MaxScanTokenSize (64k) . Incidently the newly released gpt-4.1 seems to generate tokens fast enough to go over that maximum fairly easily.

This is the construction site for the Scanner instance being overflowed:

func NewDecoder(res *http.Response) Decoder {
if res == nil || res.Body == nil {
return nil
}
var decoder Decoder
contentType := res.Header.Get("content-type")
if t, ok := decoderTypes[contentType]; ok {
decoder = t(res.Body)
} else {
scanner := bufio.NewScanner(res.Body)
decoder = &eventStreamDecoder{rc: res.Body, scn: scanner}
}
return decoder
}

Would you be able to add an option to pass a desried max size as a RequestOption?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants