Repository navigation
Integrations that act for many users (one client per request, over a shared connection pool) can now
do everything through the public API: raw requests, a shared model catalogue cache, a bounded 429
policy and the request helpers. Several card defaults were fixed (image edits, TTS voice, video
upscale scale, music quotes), and the SDK no longer copies API limits it does not need.
Breaking changes
Pre-1.0, so a minor release. Details in Changed and Fixed below.
- An explicit empty
api_keyraisesValueError(it used to fall back toDEAPI_API_KEY). - A 429 with a
Retry-Afterlonger thanmax_retry_afterraisesRateLimitErrorat once instead
of sleepingmax_retry_afterand retrying. ClientConfigrefuses negativemax_retries,max_retry_afterandpost_rate_limit_retries.- Webhook lengths are no longer checked locally: a value of a length the API refuses is a
ValidationError(422) instead of aValueError. ts_levelordiarizesendinclude_ts=Trueeven over an explicitinclude_ts=False.WebResults.request_idandcostareOptional(type checkers may flag code that assumesstr/
float).- Requests change where card defaults were fixed: image edits no longer send the card's
width/
height(the result keeps the source size), TTS may send anothervoicefor a non-default
lang, video upscale sendsscalefor ranged models, andaudio.compose_price()sendsformat
andguidance_scale. JobResult.progressisNonewhen the status response has noprogress(it used to default to
0.0), so "no progress reported" can be told from 0.video.animate()no longer refuses many reference files locally (ValueError); the API's 422
(ValidationError) states its limit.video.generate_price()takes what the quote endpoint takes:model,width,height,frames,
fps,steps,guidance.prompt,seedandnegative_promptare gone (the endpoint does not
take them and they do not change the price); passing them is aTypeError.- Values that could reach another endpoint are refused locally (
ValueError): an id with anything
but letters, digits,-and_; aclient.request()path whose percent-decoded form has..segments, slashes at the
start or backslashes; amethodother than GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS.
Realtime ignores a discoveredauth_endpointthat is not on the API's origin.
Added
client.request(method, path, *, json=None, data=None, files=None, params=None, timeout=None)on the
sync and async clients: a raw request to any endpoint (for endpoints without a typed method yet),
with the typed methods' auth, error mapping and retry policy.pathis relative to the API prefix
("images/generations"); a full URL, a..segment, a query or a fragment raisesValueError, so the
key is only ever sent tobase_url. Returns the parsed JSON body ({}when empty), not unwrapped.
Multipart bodies takedata=andfiles=(a mapping, or a sequence of pairs for a repeated field).ModelCardCache: a model catalogue cache that many clients can share (model_cache=on the sync and
async clients). A server that builds a client per user over a sharedhttp_clientfetches each
account's catalogue once instead of once per client. It keeps one catalogue per API key and
base_url(or permodel_cache_key, e.g. an account id), stored under an HMAC, never the raw key;
bounded (max_entries, least recently used evicted, with keys that never loaded held apart in
max_unconfirmed); one fetch per key at a time.ttl,miss_cooldownandretry_cooldownare
settings of the cache. Without it every client keeps its own catalogue, as before.client.models.cached_list()andcached_get(slug): the models from that cache (no request while
it is fresh). They raise the fetch error when no catalogue could be loaded.post_rate_limit_retriesclient option: how often a POST, PATCH or DELETE refused with 429 is sent
again (default:max_retries, as before;0raises the first 429).GETis not affected. With a
smallmax_retry_after, a server whose callers time out can bound the wait of a paid request and
reportRateLimitError.retry_afterinstead.DeapiError.detail: the message followed by every field error the API listed
(message [field: error; field: error]). The API's 422 message names only the first field error
(... (and 1 more error)), and some answers carry a generic message.message,errorsand the
exception types are unchanged.format_error_detail(message, errors)builds the same text.- Public helpers for requests built by hand (e.g. with
client.request()), the ones the typed
methods use:form_bool()(a multipart boolean,"1"/"0"),webhook_fields()(the webhook
fields of a job, checked locally),is_sync_transcription_unavailable(exc)(a 404 or a 422 on
modelfrom a synchronous transcription endpoint) andis_web_search_unavailable(exc)(a 404 from
a web endpoint). - File parameters (
FileInput) also take a(filename, content)or(filename, content, content_type)tuple, as httpx does: content isbytesor a binary file object; without a content
type (or withNone) it is guessed from the filename's extension. The filename is only a label;
nothing is read from disk. A single tuple passed to a list parameter (ref_images=) is one file.
Changed
- Synchronous (fast) transcription is now available to all accounts; the limited-availability
notes were removed from the docstrings, README, API reference and example. A 404 / 422 on
modelis still raised asSyncTranscriptionUnavailableError(also aNotFoundError/
ValidationError), now described as synchronous transcription not being available for the
request. - An explicit empty
api_key(""or whitespace) now raisesValueErrorinstead of falling back to
DEAPI_API_KEY; the environment is read only whenapi_keyis omitted. A server that builds a client
per user can no longer send its own key for a user whose key is empty. - A 429 whose
Retry-Afteris longer thanmax_retry_afteris raised at once asRateLimitError
(with the server'sretry_after) instead of sleepingmax_retry_afterand retrying early, which
the API would refuse again. Amax_retry_afterset low to shorten the waits now means "do not wait
longer than this; raise". ClientConfigrefuses a negativemax_retries,max_retry_afterorpost_rate_limit_retries
(ValueError).ts_levelordiarizenow always sendinclude_ts=True(transcription jobs, their quotes and
transcribe_sync()), also over an explicitinclude_ts=False: without timestamps the API drops
ts_levelback to segments and returns none, and it turns them on fordiarizeitself, so the
request and its quote now say what the API does.WebResults.request_idandWebResults.costare optional (Nonewhen the API leaves them out),
so a response without them still parses.- Webhook lengths are left to the API: a
webhook_secretorwebhook_urlof a length the API
refuses is now its 422 (ValidationErrorwitherrors["webhook_secret"]/["webhook_url"])
instead of a localValueError, so a change of the API's rules needs no SDK release. A secret
without a URL, or a URL that is not https, still raisesValueErrorbefore anything is sent. JobResult.statusaccepts the API's values (pending,processing,done,error) as
JobStatus;failed, which the current API does not send, is read aserror, so a payload that
uses it ends a wait as a failure. Any other value is kept as a plain string instead of failing to
parse (it is not terminal).JobResult.progressisNonewhen the response has none.video.animate()no longer checks the number ofref_images/ref_videos/ref_audios
against copies of the API's limits; every file is sent and the API's 422 states its limit (the
model card listsmax_ref_images,max_ref_videos,max_ref_audios,max_ref_files).video.generate_price()no longer requires aprompt, which its endpoint does not take; its
parameters are now the endpoint's (model,width,height,frames,fps,steps,
guidance), filled from the card exactly as forgenerate().- Documented that
model_cache_keymust come from an authenticated identity (e.g. the account the
key was verified to belong to): clients with the same one share a catalogue and its fetch-failure
state.video.get_description()andtranscription.get_transcript()document that a server must
not pass them a URL from an untrusted source (the download follows redirects and honours proxy
settings).
Fixed
- Image edits (
images.transform()andtransform_price()) no longer fillwidthandheightfrom
the model card. The card's size is a text-to-image default, so on a model that accepts a custom
output size the edit came back resized to it (a non-square photo returned square); without them
the API keeps the size of the (first) source image. Explicitwidth/heightare still sent
(honoured by models whose card setssupports_custom_output_size).stepsis still filled from
the card. - Text-to-speech picks a voice of the requested language. An unset
voiceused to be the card's
default voice whateverlangwas, which the API refuses when that language does not offer it
(Kokoro withlang="fr-fr"got its English defaultaf_alloy: a 422). Now the default voice is
kept only when the language lists it, otherwise the language's first voice is sent; a language the
model does not list, or one without voices, gets no voice. Models without a language list behave as
before. Applies toaudio.synthesize()andsynthesize_price(). audio.compose_price()fills from the model card whatcompose()fills (format,
inference_steps,guidance_scale), and takesformat. It used to fill onlyinference_steps,
so a quote could be checked against other values than its job (the API checks a quote as it checks
the job, and the longest duration it accepts can depend on the format). Every*_price()method
now fills exactly what its job method fills.video.upscale()andupscale_price()fill an unsetscalefrom the model card. A model with a
min_scale/max_scalerange requires it, so leaving it unset was a 422 although the docstring
said the smallest factor would be used. Now the card's default factor is sent, else the smallest of
the range, for the job and its quote alike. Models without a range (fixed factor) get noscale.transcription.transcribe_sync_price(): a quote refused because the audio is too long now gets
the same pointer to the regular transcription astranscribe_sync(), also when it was quoted from
duration_seconds(a 422 onduration_seconds, not only onsource_file). The pointer names
create_price(); the error stays aValidationErrorwith the API's message,errorsandbody.- Ids are validated before they go into a URL:
jobs.status()/jobs.get()/Joband the
keysmethods accept only ids made of letters, digits,-and_(the API's ids are UUIDs and
integers) and raiseValueErrorfor anything else, so an id can no longer reach another endpoint
or add a query. client.request()checks the path also in its fully percent-decoded form (%2e%2e,%2f,%5c,
..;xand control characters are refused like their plain forms) and accepts only GET, POST, PUT,
PATCH, DELETE, HEAD and OPTIONS asmethod(ValueErrorotherwise).- A file tuple's content type with a line break or another control character is refused
(ValueError) instead of being written into the multipart part's headers. The same check applies
to the parts given toclient.request(files=...)(their content type and extra part headers; a
header name must not contain:). client.request()refuses a path whose percent-decoded form has a query or fragment (%3F,
%23), as its docstring says, not only a literal?or#.- Realtime: the channel authorization (which carries the API key) is only sent to the
auth_endpointfromGET /websocketwhen it has the API's own origin (scheme, host and port of
base_url); any other is ignored, with a warning, and{base_url}/broadcasting/authis used. - Error text built from a response body (
message,detail) is cut to 2000 characters, ending in an
ellipsis, so an unexpected body such as an HTML error page stays bounded (a client-side bound). - A model catalogue that could not be loaded raises a fresh exception for each caller (same type and
message, its ownbody/errors) instead of the same exception object for every caller. The
failure is recorded and raised without its traceback, cause or context, and logged as text, so
nothing of the failed fetch (its frames hold the client that ran it) is kept or reaches another
client that shares the cache key.