fix: surface a clear error for nova-3 + keywords on streaming#505
Open
valeriudev wants to merge 1 commit into
Open
fix: surface a clear error for nova-3 + keywords on streaming#505valeriudev wants to merge 1 commit into
valeriudev wants to merge 1 commit into
Conversation
Opening a streaming listen.v1 connection with a nova-3 model and the
legacy `keywords` parameter used to fail silently: the socket closed
cleanly (code 1000) with no error, message, or close reason, so callers
got no signal that anything was wrong.
REST already rejects this combination with a 400 ("Keywords are not
supported for Nova-3. Please use `keyterm` instead."). This adds a
pre-connect guard that throws the same BadRequestError before dialing,
so streaming and REST behave identically — and it works in both Node and
the browser, where a failed handshake body can't be read at all.
Scope is listen.v1 streaming only: listen.v2 (flux) has no `keywords`
param, and REST already errors clearly.
Fixes deepgram#474
Fixes deepgram#470
Author
|
Heads-up for triage: this overlaps #480 (@peteroyce), which also fixes #474. The difference is #480 logs a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Opening a streaming
listen.v1connection with a nova-3 model and the legacykeywordsparameter fails silently today — the socket closes cleanly (code1000) with noerror, nomessage, and no close reason, so the caller gets zero signal that anything is wrong.REST already rejects this exact combination with a clear
400:This makes streaming behave the same way: a pre-connect guard in
WrappedListenV1Client.connectthrows the sameBadRequestErrorbefore dialing, so you get an actionable error on both transports — and it works in the browser, where a failed-handshake body can't be read at all.Fixes #474. Fixes #470. Supersedes #480 — thanks @peteroyce for the original diagnosis; this adds test coverage and throws a real error instead of only
console.warn.Before / after
Live, against the real API:
nova-3+keywordsopen=false, close=1000, err=none(silent)BadRequestError400 — "Keywords are not supported for Nova-3. Please usekeyterminstead."nova-3+keytermnova-2+keywordsThe thrown body mirrors the REST 400 body exactly (
err_code+err_msg), so streaming and REST now surface the identical error class —catch (e) { if (e instanceof BadRequestError) ... }works the same on both.Why a client-side guard, and not "propagate the handshake error"
I instrumented the unfixed streaming path and logged every event. On
nova-3 + keywordsthe SDK emits noopen, nomessage, noerror— onlyclose(1000, reason=""). There's nothing to propagate: REST returns a rich 400, but the streaming endpoint closes cleanly with zero detail. A pre-flight guard is the only mechanism that yields an actionable error, and the only one that also works in the browser.Correctness
Verified against the live API across the whole nova-3 family so the
startsWith("nova-3")check matches exactly what the server rejects — no over-blocking:keywordsnova-3,nova-3-general,nova-3-medicalnova-2,nova-2-medicalScope
listen.v1streaming only.listen.v2(flux) has nokeywordsparameter, and REST already errors clearly — neither is touched.Tests
tests/unit/keywords-nova3-guard.test.ts(9 cases): the public-client throws-matrix fornova-3/-general/-medical, plus a pure-predicate matrix for the allowed/empty cases (so no socket is opened for the cases that should succeed).Notes
src/CustomClient.tsis hand-maintained (in.fernignore), so this survives Fern regeneration; the new test file is added to.fernignorefor the same reason.close(1000). That's out of scope for this fix, but I'm happy to follow up on it separately.