Skip to content

0.8.0

Latest

Choose a tag to compare

@dawidope dawidope released this 01 Dec 12:46
36ac298

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_key raises ValueError (it used to fall back to DEAPI_API_KEY).
  • A 429 with a Retry-After longer than max_retry_after raises RateLimitError at once instead
    of sleeping max_retry_after and retrying.
  • ClientConfig refuses negative max_retries, max_retry_after and post_rate_limit_retries.
  • Webhook lengths are no longer checked locally: a value of a length the API refuses is a
    ValidationError (422) instead of a ValueError.
  • ts_level or diarize send include_ts=True even over an explicit include_ts=False.
  • WebResults.request_id and cost are Optional (type checkers may flag code that assumes str /
    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 another voice for a non-default
    lang, video upscale sends scale for ranged models, and audio.compose_price() sends format
    and guidance_scale.
  • JobResult.progress is None when the status response has no progress (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, seed and negative_prompt are gone (the endpoint does not
    take them and they do not change the price); passing them is a TypeError.
  • Values that could reach another endpoint are refused locally (ValueError): an id with anything
    but letters, digits, - and _; a client.request() path whose percent-decoded form has .. segments, slashes at the
    start or backslashes; a method other than GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS.
    Realtime ignores a discovered auth_endpoint that 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. path is relative to the API prefix
    ("images/generations"); a full URL, a .. segment, a query or a fragment raises ValueError, so the
    key is only ever sent to base_url. Returns the parsed JSON body ({} when empty), not unwrapped.
    Multipart bodies take data= and files= (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 shared http_client fetches each
    account's catalogue once instead of once per client. It keeps one catalogue per API key and
    base_url (or per model_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_cooldown and retry_cooldown are
    settings of the cache. Without it every client keeps its own catalogue, as before.
  • client.models.cached_list() and cached_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_retries client option: how often a POST, PATCH or DELETE refused with 429 is sent
    again (default: max_retries, as before; 0 raises the first 429). GET is not affected. With a
    small max_retry_after, a server whose callers time out can bound the wait of a paid request and
    report RateLimitError.retry_after instead.
  • 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, errors and 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
    model from a synchronous transcription endpoint) and is_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 is bytes or a binary file object; without a content
    type (or with None) 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
    model is still raised as SyncTranscriptionUnavailableError (also a NotFoundError /
    ValidationError), now described as synchronous transcription not being available for the
    request.
  • An explicit empty api_key ("" or whitespace) now raises ValueError instead of falling back to
    DEAPI_API_KEY; the environment is read only when api_key is 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-After is longer than max_retry_after is raised at once as RateLimitError
    (with the server's retry_after) instead of sleeping max_retry_after and retrying early, which
    the API would refuse again. A max_retry_after set low to shorten the waits now means "do not wait
    longer than this; raise".
  • ClientConfig refuses a negative max_retries, max_retry_after or post_rate_limit_retries
    (ValueError).
  • ts_level or diarize now always send include_ts=True (transcription jobs, their quotes and
    transcribe_sync()), also over an explicit include_ts=False: without timestamps the API drops
    ts_level back to segments and returns none, and it turns them on for diarize itself, so the
    request and its quote now say what the API does.
  • WebResults.request_id and WebResults.cost are optional (None when the API leaves them out),
    so a response without them still parses.
  • Webhook lengths are left to the API: a webhook_secret or webhook_url of a length the API
    refuses is now its 422 (ValidationError with errors["webhook_secret"] / ["webhook_url"])
    instead of a local ValueError, 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 raises ValueError before anything is sent.
  • JobResult.status accepts the API's values (pending, processing, done, error) as
    JobStatus; failed, which the current API does not send, is read as error, 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.progress is None when the response has none.
  • video.animate() no longer checks the number of ref_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 lists max_ref_images, max_ref_videos, max_ref_audios, max_ref_files).
  • video.generate_price() no longer requires a prompt, 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 for generate().
  • Documented that model_cache_key must 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() and transcription.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() and transform_price()) no longer fill width and height from
    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. Explicit width/height are still sent
    (honoured by models whose card sets supports_custom_output_size). steps is still filled from
    the card.
  • Text-to-speech picks a voice of the requested language. An unset voice used to be the card's
    default voice whatever lang was, which the API refuses when that language does not offer it
    (Kokoro with lang="fr-fr" got its English default af_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 to audio.synthesize() and synthesize_price().
  • audio.compose_price() fills from the model card what compose() fills (format,
    inference_steps, guidance_scale), and takes format. It used to fill only inference_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() and upscale_price() fill an unset scale from the model card. A model with a
    min_scale / max_scale range 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 no scale.
  • transcription.transcribe_sync_price(): a quote refused because the audio is too long now gets
    the same pointer to the regular transcription as transcribe_sync(), also when it was quoted from
    duration_seconds (a 422 on duration_seconds, not only on source_file). The pointer names
    create_price(); the error stays a ValidationError with the API's message, errors and body.
  • Ids are validated before they go into a URL: jobs.status() / jobs.get() / Job and the
    keys methods accept only ids made of letters, digits, - and _ (the API's ids are UUIDs and
    integers) and raise ValueError for 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,
    ..;x and control characters are refused like their plain forms) and accepts only GET, POST, PUT,
    PATCH, DELETE, HEAD and OPTIONS as method (ValueError otherwise).
  • 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 to client.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_endpoint from GET /websocket when 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/auth is 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 own body / 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.