API reference
@speechineer/js
The configuration and data types every Speechineer package shares. Whichever package you install, these are the same: how you configure the client, how you describe the form to fill, the callbacks that deliver values and progress, the errors and events that report problems, and the state every session reports.
The package for your framework documents its own functions; everything those functions' options are built from is described here, once.
Setup
Create the client once, at app startup, with your credentials — every session
starts from it. Without a baseUrl it talks to the production Speechineer API.
SpeechineerClient
Your connection to Speechineer. Create one with createClient and keep it for the lifetime of your app; every session starts from it.
Methods
speechToForm()
speechToForm(options): SpeechToFormSession;Fill a form by voice. Returns the session; call start() on it when the user is
ready to speak. In React and Angular use useSpeechToForm / injectSpeechToForm
instead — they take the same options and manage the session for you.
Parameters
| Parameter | Type |
|---|---|
options | SpeechToFormOptions |
Returns
SpeechToFormSession
textToForm()
textToForm(options): TextToFormSession;Extract field values from text — no microphone involved. Returns the session;
call extract(text) as often as you like. In React and Angular use
useTextToForm / injectTextToForm.
Parameters
| Parameter | Type |
|---|---|
options | TextToFormOptions |
Returns
TextToFormSession
Properties
| Property | Type | Description |
|---|---|---|
baseUrl | string | The API root this client talks to (no trailing slash). |
uiLanguage? | "en" | "de" | The language people are shown messages in, as the app asked for it — undefined when it did not. Deliberately not defaulted here. It travels to Speechineer as the session's language, and sending nothing is meaningful: Speechineer then negotiates from the browser's Accept-Language, which is a better answer than any guess this SDK could make (the header can say de-CH,de;q=0.9 while navigator.language says en-US). A session overrides it with its own uiLanguage. The SDK's own handful of messages still need a concrete language even when this is undefined — see negotiateSdkLanguage, which is the fallback for those only. |
ClientOptions
How the SDK reaches Speechineer and on whose behalf. Pass it once to
createClient (or to the React provider / Angular provideSpeechineer).
Fill in one of the two credential styles:
apiKey(+account) — for an Unsigned API key. The SDK builds the token for you. Convenient for development, but the key is readable in your frontend.token— for a Signed API key. Your server signs a short-lived token per user and you hand it over (a string, or a function that fetches one); the SDK forwards it untouched, because signing requires a private key that must never reach the browser. Use this in production.
Properties
| Property | Type | Description |
|---|---|---|
baseUrl? | string | The Speechineer API root, without a trailing slash. Defaults to the production API — set it only to target another environment. |
apiKey? | string | The API key of the workspace this app belongs to. Unsigned mode only — with a signed token the key travels inside the token. |
token? | string | TokenProvider | A token your server signed, or a function that returns one. Takes precedence over apiKey, and is the only option a Signed API key accepts. With a function the SDK asks for a fresh token on every session start, so expiry is never your problem. |
account? | Account | The end user sessions are for, unless a session says otherwise. Required with apiKey; ignored with token (the token carries the account). |
uiLanguage? | "en" | "de" | The language to show people messages in — 'en' or 'de', defaulting to English. It reaches two places. Every userMessage Speechineer sends is already translated into it, because the language travels with the session; and the handful of messages the SDK writes itself (a denied microphone, an unreachable service) are rendered in it too. Developer messages stay English, since they are for you. Set it once here and every session follows. If you do not, Speechineer falls back to the browser's Accept-Language and then to English. |
DEFAULT_BASE_URL
const DEFAULT_BASE_URL: "https://ai.speechineer.com/api" = 'https://ai.speechineer.com/api';Where the SDK sends its requests unless createClient({ baseUrl }) says
otherwise — the production Speechineer API.
createClient()
function createClient(options?): SpeechineerClient;Create the client once, at app startup, and create every session from it.
Parameters
| Parameter | Type |
|---|---|
options | ClientOptions |
Returns
Example
import { createClient } from "@speechineer/js";
// Development — an unsigned workspace key + who the end user is:
const speechineer = createClient({ apiKey: "spnr_live_…", account: { key: user.id } });
// Production — your server signs a short-lived token per user:
const speechineer = createClient({ token: () => fetch("/api/speechineer-token").then((r) => r.text()) });Authentication
Who is calling: your workspace's API key plus an identifier for the end user, or a token your server signed (a string, or a function that fetches a fresh one).
Account
The end user a session is for. Usage and per-account limits are tracked against it, so avoid one shared value for everybody.
Properties
| Property | Type | Description |
|---|---|---|
key | string | A stable id for the end user — your own user id works well. |
pseudonym? | string | An optional readable label for that account, shown in your workspace instead of the raw id (for example a team or desk name). |
TokenProvider
type TokenProvider = () => string | Promise<string>;Returns a token your server signed for the current user — called every time a session is created or resumed, so a fresh, short-lived token is always used.
Returns
string | Promise<string>
Forms
Which form to fill and where its definition lives: configured in Speechineer (a workspace form — your code names it) or defined in your code (an inline form — fields, prompts, and model configurations ship with the call).
FormIdentity
The identity every form carries, whichever side defines it.
Extended by
Properties
| Property | Type | Description |
|---|---|---|
key | string | The form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form. |
version | string | Which version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready. |
language | string | The language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks. |
WorkspaceForm
A form configured in Speechineer. Your code names it, and the fields, prompts and models
come from your workspace — change them there without shipping a release. Individual fields
can be marked in your workspace as set by code, and those arrive through fieldConfigs.
Extends
Properties
| Property | Type | Description |
|---|---|---|
key | string | The form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form. |
version | string | Which version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready. |
language | string | The language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks. |
source | "workspace" | The definition lives in your Speechineer workspace. |
fieldConfigs? | FieldSpec[] | Configuration for the fields your form marks as set by your code — a choice field whose options come from your own data, for example. Build each one with FormFieldConfig, giving it the same field id it has in your workspace. Only the marked fields are read from here, and one of them missing stops the session from starting. Every other field keeps the definition it has in your workspace. |
Prompts
The prompts an inline form supplies, one per slot: how to transcribe, and how to extract the field values. Each is plain-language instruction text. Omit a slot to use the default.
Properties
| Property | Type | Description |
|---|---|---|
transcription? | string | Guidance for the transcription step (vocabulary, domain, style). |
extraction? | string | Guidance for turning the transcript into field values. |
Models
The model configurations an inline form pins, one per slot, by the keys you gave them in your workspace. Omit a slot to use the workspace default.
Properties
| Property | Type | Description |
|---|---|---|
transcription? | string | The model configuration key for transcription. |
extraction? | string | The model configuration key for extraction. |
InlineForm
A form defined in your code: you declare the fields to extract (build them with
FormField) and, optionally, the prompts and model configurations to use.
Speechineer records it under key / version in your workspace.
Extends
Properties
| Property | Type | Description |
|---|---|---|
key | string | The form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form. |
version | string | Which version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready. |
language | string | The language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks. |
source | "inline" | The definition lives in your code. |
fields | FieldSpec[] | Fields to extract — build with FormField. |
prompts? | Prompts | Custom prompts per slot. |
models? | Models | Model configurations per slot, by workspace key. |
FormDefinition
type FormDefinition = WorkspaceForm | InlineForm;Where the form comes from: the one configured in Speechineer (source: 'workspace')
or the one your code defines (source: 'inline'). Every capability that fills a
form takes one of these as form.
Fields
What to extract and how to describe it. Build each field of an inline form with
FormField; the prompt is the instruction Speechineer follows for that field.
OptionsFieldConfig
The allowed options of a choice field (select / multiselect).
Properties
| Property | Type | Description |
|---|---|---|
kind | "options" | Marks the options configuration. |
options | string[] | The values the user may choose from. |
appendOptionsToPrompt? | boolean | Append the options to the prompt so the extraction sees them as part of the instruction. |
RangeFieldConfig
The [min, max] range of a slider field.
Properties
| Property | Type | Description |
|---|---|---|
kind | "range" | Marks the range configuration. |
range | [number, number] | The lowest and highest value allowed. |
FieldSpec
One field to extract. Build these with FormField rather than by hand —
the factory picks the right type and validates the options for you.
Properties
| Property | Type | Description |
|---|---|---|
id | string | Your id for the field. It comes back with every value — in values and in onFieldValue. |
prompt | string | What to extract, in plain language — "Extract the patient's full name". This instruction is what makes the difference between a good and a poor result, so be specific about the value you want. |
type | FieldType | The kind of value expected, which also shapes how it is normalized. |
config? | FieldConfig | Extra rules for types that need them: the options of a choice, or a slider range. |
FieldFactory
The field factory surface. Every helper returns a ready FieldSpec.
Methods
text()
text(id, prompt): FieldSpec;Free-form text.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
textarea()
textarea(id, prompt): FieldSpec;Multi-line free-form text; same value semantics as text.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
email()
email(id, prompt): FieldSpec;An email address.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
phone()
phone(id, prompt): FieldSpec;A phone number.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
url()
url(id, prompt): FieldSpec;A URL.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
integer()
integer(id, prompt): FieldSpec;A whole number.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
float()
float(id, prompt): FieldSpec;A decimal number.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
checkbox()
checkbox(id, prompt): FieldSpec;A yes/no value.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
date()
date(id, prompt): FieldSpec;A calendar date.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
time()
time(id, prompt): FieldSpec;A time of day.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
datetime()
datetime(id, prompt): FieldSpec;A date with a time.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
Returns
slider()
slider(
id,
prompt,
range): FieldSpec;Ranged numeric field; range is [min, max] with min < max.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
range | [number, number] |
Returns
select()
select(
id,
prompt,
options,
appendOptionsToPrompt?): FieldSpec;Single-choice; options must be non-empty.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
options | string[] |
appendOptionsToPrompt? | boolean |
Returns
multiselect()
multiselect(
id,
prompt,
options,
appendOptionsToPrompt?): FieldSpec;Multi-choice; options must be non-empty.
Parameters
| Parameter | Type |
|---|---|
id | string |
prompt | string |
options | string[] |
appendOptionsToPrompt? | boolean |
Returns
FieldConfigFactory
The factory surface for configuring a workspace form's code-defined fields. Only the three types that take a configuration appear here — the rest have nothing for code to supply.
Methods
slider()
slider(id, range): FieldSpec;Ranged numeric field; range is [min, max] with min < max.
Parameters
| Parameter | Type |
|---|---|
id | string |
range | [number, number] |
Returns
select()
select(
id,
options,
appendOptionsToPrompt?): FieldSpec;Single-choice; options must be non-empty.
Parameters
| Parameter | Type |
|---|---|
id | string |
options | string[] |
appendOptionsToPrompt? | boolean |
Returns
multiselect()
multiselect(
id,
options,
appendOptionsToPrompt?): FieldSpec;Multi-choice; options must be non-empty.
Parameters
| Parameter | Type |
|---|---|
id | string |
options | string[] |
appendOptionsToPrompt? | boolean |
Returns
FieldConfig
type FieldConfig =
| OptionsFieldConfig
| RangeFieldConfig;The extra configuration a field type may carry: the allowed options of a choice field, or the range of a slider.
FieldType
type FieldType =
| "text"
| "textarea"
| "email"
| "phone"
| "url"
| "integer"
| "float"
| "slider"
| "checkbox"
| "select"
| "multiselect"
| "date"
| "time"
| "datetime"
| "template";FIELD_TYPES
const FIELD_TYPES: readonly ["text", "textarea", "email", "phone", "url", "integer", "float", "slider", "checkbox", "select", "multiselect", "date", "time", "datetime"];The field types you can declare, in presentation order. Use it to build a type picker without redeclaring the list.
FormField
const FormField: FieldFactory;Build the fields of an inline form. A factory object (no new, tree-shakeable)
producing FieldSpecs, with light runtime validation for the config-bearing types.
Example
import { FormField } from "@speechineer/js"; // also exported by @speechineer/react and @speechineer/angular
const fields = [
FormField.text("patientName", "Extract the patient full name"),
FormField.integer("age", "Extract the age in years"),
FormField.select("species", "Extract the species", ["Canine", "Feline", "Equine"]),
FormField.slider("painLevel", "Extract the pain level", [0, 10]),
];FormFieldConfig
const FormFieldConfig: FieldConfigFactory;Configure the fields your workspace form marks as set by your code — a choice field whose
options come from your own data, for example. Pass the results as the form's fields.
Same validation as FormField, without the prompt: what to extract is already written in
your workspace, so only the field id and the configuration come from here.
Example
import { FormFieldConfig } from "@speechineer/js"; // also exported by @speechineer/react and @speechineer/angular
const form = {
source: "workspace",
key: "intake",
version: "1",
language: "en",
fields: [FormFieldConfig.select("species", await loadSpeciesFromMyDatabase())],
} as const;Callbacks
Optional hooks for imperative integrations. Everything they report — values, the transcript, events, errors — is also in the session state.
SessionCallbacks
The callbacks every session accepts. All of them are optional: a session runs without any, and you add the ones your integration reacts to. Everything they report is also visible in the session state, so a UI that renders from the state needs none of them.
Properties
| Property | Type | Description |
|---|---|---|
onSessionStart? | (sessionId) => void | Fires once, as soon as the session exists and work can begin. Receives the session id — keep it if you want to correlate it with your own logs. |
onStateChange? | (state) => void | The session state changed — its lifecycle, its id, a value, the transcript, an error, or the status of one of its connections. Receives the whole new state; render from it. |
onEvent? | (event) => void | Everything Speechineer reports for this session, at every level, failures included. One stream for logging or a live status display. event.level tells you what you have: 'error' means the session is over, and the other three are advisory. If you only want one level, take the matching hook below instead. |
onError? | (error) => void | Something failed in a way you should handle: a rejected request, a denied microphone permission, a lost connection, or a failure Speechineer reported while the session ran. Branch on error.code for the exact cause, or on the error's class (SpeechineerQuotaError, SpeechineerRuntimeError, …) to handle a whole family at once. Fires once per failure, so one rejected request reporting several problems calls this several times — the same list you can read as errors in the session state. |
onWarning? | (notice) => void | Something did not go as asked, but the session carried on — a setting Speechineer could not honour, a connection it refused, a component that had to retry. Worth surfacing or logging; never fatal. |
onInfo? | (notice) => void | A step worth reporting — a phase of the work starting or finishing. |
onDebug? | (notice) => void | Trace-level detail, for diagnosing an integration. Only arrives if the session is running at debug; otherwise Speechineer never sends it, so this stays silent rather than being filtered here. |
FormValueCallbacks
Field-value callbacks, added by every capability that fills a form. Optional —
the latest value of every field is always available as values in the
session state; use the callback to push values into a form library
imperatively.
Properties
| Property | Type | Description |
|---|---|---|
onFieldValue? | (fieldId, value) => void | One recognized field value. Called repeatedly while the user speaks, and more than once for the same fieldId when a value is refined — always apply the latest. fieldId is the id you gave the field; value is passed through as received, so cast or validate it the way your form expects. |
TranscriptCallbacks
Transcript callbacks, added by every capability that returns the spoken text.
Optional — the transcript so far is always available as transcript in the
session state.
Properties
| Property | Type | Description |
|---|---|---|
onTranscript? | (text) => void | The transcript so far — the full accumulated text, not just the newest words, so you can render it directly without stitching updates together. |
Events and errors
What you receive when something noteworthy or fatal happens during a session: a typed error with a stable code, and the stream of status events.
SpeechineerClientError
Your app's own mistake, caught before anything was sent — missing credentials, an action
before start(), or a microphone the browser would not give up.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerAuthError
The credentials were missing, malformed, expired, or rejected.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerQuotaError
A usage allowance is spent. meta carries the ceiling that bound and how much of it was
used — see QuotaMeta.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerAccessError
The credentials are valid but not allowed to do this.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerNotFoundError
Something named in the request does not exist — a form, a version, or a session whose id answers to nothing because it was never created or has long since ended and been swept.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerConflictError
The request conflicts with the current state — for example an action whose prerequisite has not happened yet.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerValidationError
The request was not acceptable. When several things are wrong at once you get one error per
cause in state.errors, so a rejected form tells you everything in one round trip.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerMethodError
The path is right but the HTTP method is not one it accepts. A mistake in how the request was built, not in what it asked for.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerNotAcceptableError
Nothing that can be returned matches the Accept header the request sent.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerTooLargeError
The request body is larger than the endpoint will read. Send less, or send it in parts.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerUnsupportedMediaError
The body's content type is not one the endpoint reads. The body itself may be perfectly well-formed — it is the type that is not supported.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerRateLimitError
Too many requests. Slow down and retry.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerRuntimeError
A running session stopped because something failed — transcription or field extraction could not be restarted. The session is over; offer the user a fresh start.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerServiceError
Speechineer could not handle the request, for a reason that is not your app's doing. Retrying the same request may work.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerUpstreamError
A service Speechineer depends on answered with something unusable. Retrying the same request the same way is unlikely to help.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerUnavailableError
Speechineer is temporarily unreachable. Nothing is wrong with your request — retry later.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
SpeechineerTimeoutError
The request took too long to complete. Retrying is reasonable.
Extends
Properties
| Property | Type | Description |
|---|---|---|
level | "error" | Always 'error': a failure is the terminal level, by definition. |
type | string | The category. Prefer catching the matching subclass over comparing this yourself. |
code | string | A stable identifier for what went wrong. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
meta | Record<string, unknown> | null | Data belonging to this failure — the shape depends on code. |
cause? | unknown | The underlying failure, when there was one. |
name | string | The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class. |
message | string | For you, in English: what went wrong and what to do about it. Log this one. |
stack? | string | Where the failure was raised, when the browser provides it. |
QuotaMeta
The meta a SpeechineerQuotaError carries: the allowance that bound, and how much
of it was used.
The amounts are decimal strings, not numbers — usage is metered in fractional units and a JSON number would round them.
Properties
| Property | Type | Description |
|---|---|---|
limit | string | The ceiling that bound. |
used | string | How much of it had been used. |
remaining | string | What was left. |
layer | string | Which allowance bound — for example an account's monthly budget. |
SpeechineerEvent
Anything Speechineer reports, at any level — a failure, a warning, a progress note.
This is what onEvent receives, so it is the one shape worth learning. level is the
terminality: 'error' means the session is over and nothing else does, so you never have to
inspect a code to find out whether you can keep going.
Extended by
Properties
| Property | Type | Description |
|---|---|---|
level | "debug" | "info" | "warning" | "error" | 'error' means the session ended. The other three are advisory. |
type | string | The category — handle a whole family at once without enumerating codes. |
code | string | A stable identifier for what happened. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
message | string | For you: what happened and what to do about it. Belongs in your logs. |
meta | Record<string, unknown> | null | Data belonging to this particular event — the shape depends on code. |
SessionNotice
One thing that happened while the session kept running — delivered to onWarning, onInfo
or onDebug, and to onEvent along with everything else.
Notices are advisory by definition: a connection re-establishing itself, a setting the service
could not honour as asked, a stage of the work finishing. Anything that ends the session is
not a notice — it arrives as a SpeechineerError through onError and state.errors.
Identical to SpeechineerEvent but for the narrower level; it adds no fields, because
the event is the whole report.
Extends
Properties
| Property | Type | Description |
|---|---|---|
type | string | The category — handle a whole family at once without enumerating codes. |
code | string | A stable identifier for what happened. Branch on this, not on a message. |
userMessage | string | For the person using your app, in the session's language. Show this one. |
message | string | For you: what happened and what to do about it. Belongs in your logs. |
meta | Record<string, unknown> | null | Data belonging to this particular event — the shape depends on code. |
level | "debug" | "info" | "warning" | Never 'error' — a notice that ended the session would be a contradiction. |
SpeechineerErrorCode
type SpeechineerErrorCode =
| keyof typeof SDK_ERRORS
| string & {
};A stable identifier for what went wrong.
The union lists what this version knows about but stays open on purpose: Speechineer can name a new failure without every app upgrading first, so the type must not claim the list is closed.
EventLevel
type EventLevel = LevelSdk;How severe something is — and, for error, that the session is over.
There is no critical: nothing ever emitted one, and it named a severity no handler treated
differently from error.
SDK_ERROR_CODES
const SDK_ERROR_CODES: readonly (
| "NO_AUTH"
| "NO_ACCOUNT"
| "NO_CLIENT"
| "NO_SESSION"
| "MICROPHONE_DENIED"
| "MICROPHONE_UNAVAILABLE"
| "AUDIO_UNSUPPORTED"
| "NETWORK"
| "UNKNOWN"
| "REQUEST_FAILED")[];The codes the SDK names itself, as opposed to the ones Speechineer sends.
Useful for telling the two apart — "did this request even leave the browser?" is a different
question from "what did Speechineer say?", and it changes what you do about it. A code in this
list means nothing was sent: a missing credential, a denied microphone, a browser that cannot
record. The one exception is REQUEST_FAILED, which means Speechineer was reached but
answered in a shape that carried no code of its own.
Example
import { SDK_ERROR_CODES } from "@speechineer/js";
onError: (error) => {
const isLocal = (SDK_ERROR_CODES as readonly string[]).includes(error.code);
if (isLocal) showSetupHint(error);
else reportToSupport(error.code, session.getState().requestId);
};SpeechineerError
Something Speechineer could not do. The session is over.
Branch on code — it is stable — or catch a subclass to handle a whole category at once
(SpeechineerQuotaError covers every way an allowance can run out).
Two messages, for two readers. userMessage is written for the person using your app and
arrives already translated into the session's language — show that one. message is written
for you: it says what to do about the failure, and belongs in your logs rather than on screen.
It is also a SpeechineerEvent with level: 'error', which is why onEvent can
receive failures and notices alike.
Extends
Error
Extended by
SpeechineerAccessErrorSpeechineerAuthErrorSpeechineerClientErrorSpeechineerConflictErrorSpeechineerMethodErrorSpeechineerNotAcceptableErrorSpeechineerNotFoundErrorSpeechineerQuotaErrorSpeechineerRateLimitErrorSpeechineerRuntimeErrorSpeechineerServiceErrorSpeechineerTimeoutErrorSpeechineerTooLargeErrorSpeechineerUnavailableErrorSpeechineerUnsupportedMediaErrorSpeechineerUpstreamErrorSpeechineerValidationError
Implements
Constructors
Constructor
new SpeechineerError(options): SpeechineerError;Parameters
| Parameter | Type |
|---|---|
options | SpeechineerErrorOptions |
Returns
Overrides
Error.constructorProperties
level
readonly level: "error";Always 'error': a failure is the terminal level, by definition.
Implementation of
type
readonly type: string;The category. Prefer catching the matching subclass over comparing this yourself.
Implementation of
code
readonly code: string;A stable identifier for what went wrong. Branch on this, not on a message.
Implementation of
userMessage
readonly userMessage: string;For the person using your app, in the session's language. Show this one.
Implementation of
meta
readonly meta: Record<string, unknown> | null;Data belonging to this failure — the shape depends on code.
Implementation of
cause?
readonly optional cause?: unknown;The underlying failure, when there was one.
name
readonly name: string;The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
Overrides
Error.namemessage
readonly message: string;For you, in English: what went wrong and what to do about it. Log this one.
Implementation of
Overrides
Error.messagestack?
readonly optional stack?: string;Where the failure was raised, when the browser provides it.
Overrides
Error.stackSession state
What a running session reports about itself — its lifecycle, its id, the last error, the latest values, the transcript, whether it is listening, and whether each of its connections is open. The same shape in every framework: read it, subscribe to it, render from it.
ConnectionState
The state of one connection.
Properties
| Property | Type |
|---|---|
status | ConnectionStatus |
SessionState
Everything a session reports about itself. Read it with getState(), receive it
through subscribe / onStateChange, or — in React and Angular — take it from the
hook / inject result. Render your UI from it. The object is immutable — every change
produces a new one — so it is safe to compare by reference.
Properties
| Property | Type | Description |
|---|---|---|
status | SessionStatus | Where the session is in its life — see SessionStatus. |
sessionId | string | null | The id of the running session, or null before it exists. |
errors | readonly SpeechineerError[] | Everything that has failed, root cause first — empty when nothing has. A single request can report several problems at once (a rejected form names every offending field), and a session that ends reports the one failure that ended it. Read errors[0] for the cause to show; the rest is the context it arrived with. Cleared when the next start() succeeds. |
requestId | string | null | The id of the most recent answer, or null. Quote it when reporting a problem: the same id follows the request through every part of Speechineer that handled it. |
connections | SessionConnections | The status of each connection: session always, the others when the capability uses them. |
values | Readonly<Record<string, unknown>> | The latest recognized value of every field, keyed by the field id you gave it. Starts with initialValues (if any) and grows as values are recognized; a refined value replaces the earlier one. |
transcript | string | The spoken text so far (the full accumulated transcript), or '' when the session does not stream it. |
isListening | boolean | The microphone is on and audio is being sent. |
isConnecting | boolean | The session or one of its connections is being established. |
isEnding | boolean | The session is being finished (end()), or the microphone is winding down after stop(). |
SessionStatus
type SessionStatus = "idle" | "starting" | "active" | "recovering" | "ending" | "failed";Where the session is in its life.
idle— nothing started yet (or the session was ended).starting— the session is being created and its connection opened.active— the session exists;isListeningandconnectionstell you what it is doing.recovering— the session vanished on the server and is being resumed.ending—end()is discarding the session.failed— the session is not usable: starting or recovering did not succeed, or a running session ended because something failed (a crash, a spent allowance). Seeerrors;errors[0].codesays which.start()may be called again.
ConnectionStatus
type ConnectionStatus = "closed" | "connecting" | "open" | "closing";Whether one connection of the session is open. closing is reported by the
microphone connection between stop() and the moment capture has fully wound down.
ConnectionKey
type ConnectionKey = "session" | "audio" | "results" | "transcript";The connections a session may have. session is the main connection every
session has — when it is lost, every other connection is closed as well.
audio carries the microphone, results the recognized values, transcript
the spoken text. A session only lists the connections its capability uses.
SessionConnections
type SessionConnections = {
session: ConnectionState;
} & Readonly<Partial<Record<Exclude<ConnectionKey, "session">, ConnectionState>>>;The connections of a session: session always, the others only when the
capability uses them.
Type Declaration
| Name | Type |
|---|---|
session | ConnectionState |
Type Aliases
SdkLanguage
type SdkLanguage = typeof SDK_LANGUAGES[number];A language the SDK can speak.
Variables
SDK_LANGUAGES
const SDK_LANGUAGES: readonly ["en", "de"];The languages the SDK can render its own sentences in. The service translates its own.
DEFAULT_SDK_LANGUAGE
const DEFAULT_SDK_LANGUAGE: SdkLanguage = 'en';The language used when nothing else answers — the same fallback the service ends on.