{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"TypeScript SDK (@bria-ai/client)","description":"Generate and edit images and video with Bria's FIBO models through a REST API, Python and TypeScript SDKs, MCP server and agent skills. Licensed training data, controllable output, provenance on every result.","siteUrl":"https://docs.bria.ai","image":"/assets/bria-social-card.5f3c59395e7b5efa776984c64ef9cb0956b1d651f45b7ebf9502122a66054f35.db81178d.png","llmstxt":{"hide":false,"title":"Bria API documentation","description":"Bria's developer platform: controllable, commercially safe visual generative AI (images and video) as a REST API, Python and TypeScript SDKs, MCP server and agent skills.","details":{"path":"_llmstxt-details.md"},"sections":[{"title":"Getting started","description":"First call, authentication, async jobs and webhooks, rate limits, inputs.","includeFiles":["index.md","getting-started/quickstart.md","getting-started/authentication.md","getting-started/async-requests.md","status.yaml","getting-started/rate-limits-and-errors.md","getting-started/working-with-images.md","getting-started/asset-retention.md"]},{"title":"Integrate","description":"Python SDK, TypeScript SDK, MCP server, agent skills, and machine-readable docs for agents.","includeFiles":["integration-methods/python-sdk.md","integration-methods/typescript-sdk.md","MCP-authentication.md","integration-methods/bria-skill.md","integration-methods/for-ai-agents.md"]},{"title":"Concepts","description":"Platform map, VGL and the FIBO models, safety, best practices.","includeFiles":["products-overview.md","VGL.md","safety.md","best-practices-overview.md","image-generation-best-practices.md","image-editing-best-practices.md","product-shots-best-practices.md"]},{"title":"Image Generation","description":"Generate images from text, reference images or structured (VGL) prompts with FIBO.","includeFiles":["image-generation-overview.md","image-generation.yaml"]},{"title":"Image Editing","description":"Instruction-based editing plus specialized endpoints for backgrounds, erasing, fill, expansion, upscaling and style.","includeFiles":["image-editing-overview.md","image-editing.yaml"]},{"title":"Product Shot Editing","description":"Cutouts, packshots, shadows, lifestyle scenes, product integration, holding, virtual try-on, automotive.","includeFiles":["product-shot-overview.md","product-shot-editing.yaml"]},{"title":"Video Editing","description":"Background removal (REST or real-time streaming), erasing, upscaling and masks for video; local video upload.","includeFiles":["video-editing-overview.md","local-video-upload-service.md","streaming-rmbg.md","video-editing.yaml"]},{"title":"Ad Delayer","description":"Turn a flat ad into editable layers; the guide holds the layer document contract.","includeFiles":["ad-delayer-overview.md","ad-delayer.yaml"]},{"title":"Trust and provenance","description":"Public verification of Bria provenance, and attribution of outputs to licensed training data.","includeFiles":["trust-and-provenance-overview.md","visual-verification-overview.md","visual-verification.yaml","enterprise/attribution.md","bria-attribution-service.yaml"]},{"title":"Enterprise","description":"Run Bria in your own cloud or on-premises.","includeFiles":["enterprise/deployment-options.md"]}],"excludeFiles":["_llmstxt-details.md","README.md"]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"typescript-sdk-bria-aiclient","__idx":0},"children":["TypeScript SDK (@bria-ai/client)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.npmjs.com/package/@bria-ai/client"},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["@bria-ai/client"]}]}," is Bria's official TypeScript and JavaScript SDK. It wraps the v2 REST API with a single async client, handles the async job lifecycle (submit, poll, webhooks), retries transient failures, and converts local images to API inputs for you. It mirrors the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/integration-methods/python-sdk"},"children":["Python SDK"]},": same method names, same behavior."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Source and issues: ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/Bria-AI/bria-client"},"children":["github.com/Bria-AI/bria-client"]}," (MIT)"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Node.js 20 or newer. No runtime dependencies: it uses the built-in ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["fetch"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FormData"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Blob"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Ships ESM and CommonJS builds with type declarations."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Covers every v2 endpoint. Legacy ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/v1"]}," endpoints are not reachable through the SDK; call them with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["fetch"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"install-and-authenticate","__idx":1},"children":["Install and authenticate"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"npm install @bria-ai/client\nexport BRIA_API_TOKEN=\"<your-bria-api-token>\"\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The client reads ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BRIA_API_TOKEN"]}," from the environment. You can also pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["apiToken"]}," to the constructor, or override it per call with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["apiToken"]}," in the options of any method. Get a token from the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://platform.bria.ai/organization-management/api-keys"},"children":["Bria Console"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"your-first-call","__idx":2},"children":["Your first call"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { BriaClient, Image } from \"@bria-ai/client\";\n\nconst client = new BriaClient();\n\nconst response = await client.run(\"image/edit/remove_background\", {\n  image: new Image(\"https://labs-assets.bria.ai/sandbox-example-inputs/remove_background_example.jpg\").asBriaApiInput,\n});\n\nconsole.log(response.status); // COMPLETED\nconsole.log(response.result?.image_url); // URL of the cutout\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The first argument is the v2 path without the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/v2/"]}," prefix, exactly as it appears in the API reference: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["image/generate"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["image/edit/remove_background"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["video/edit/remove_background"]},", and so on."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"one-client","__idx":3},"children":["One client"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["JavaScript has no synchronous HTTP, so there is a single ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaClient"]}," and every method returns a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Promise"]},". Where the Python SDK offers ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaSyncClient"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaAsyncClient"]},", here you ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["await"]}," (or run many calls with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Promise.all"]},")."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"three-request-methods","__idx":4},"children":["Three request methods"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Bria's v2 endpoints are asynchronous by default. The SDK gives you three ways to work with that:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Method"},"children":["Method"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"What it does"},"children":["What it does"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Returns"},"children":["Returns"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.run(endpoint, payload, options?)"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Sends the request with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sync: true"]}," and resolves when the result is ready. Simplest for interactive use."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaResponse"]}," with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.submit(endpoint, payload, options?)"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Sends the request with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sync: false"]}," and resolves immediately. Pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["webhookUrl"]}," in the options to be called back."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaResponse"]}," with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestId"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["statusUrl"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.poll(responseOrRequestId, options?)"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Polls the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/status"},"children":["status endpoint"]}," until the job finishes. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["interval"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["timeout"]}," are in seconds (defaults 1 and 60). Throws when the timeout elapses."]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaResponse"]}," with ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Do not put ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sync"]}," in your payload; ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["run"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submit"]}," set it for you and throw if you pass it."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"// Submit now, collect later\nconst job = await client.submit(\"video/segment/mask_by_prompt\", { video: videoUrl, prompt: \"the red car\" });\nconsole.log(\"submitted:\", job.requestId);\n\nconst final = await client.poll(job, { interval: 2, timeout: 600 });\nconsole.log(final.result?.video_url);\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.status(requestId)"]}," returns just the current status (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IN_PROGRESS"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["COMPLETED"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ERROR"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UNKNOWN"]},") if you manage polling yourself. Every method also accepts an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["AbortSignal"]}," as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["signal"]}," to cancel a call."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"responses-and-errors","__idx":5},"children":["Responses and errors"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Every method returns a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaResponse"]},":"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Field"},"children":["Field"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestId"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Job identifier; also the deduplication key for webhooks"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["IN_PROGRESS"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["COMPLETED"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ERROR"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["UNKNOWN"]}," (the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Status"]}," enum)"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Endpoint result as an open object, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]}," until the job completes: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result?.image_url"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result?.video_url"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result?.seed"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["result?.structured_prompt"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["code"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["message"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["details"]}," when the request failed, otherwise ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["statusUrl"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Polling URL for async jobs"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pass ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["raiseForStatus: true"]}," to turn API errors into a thrown ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaException"]}," instead of inspecting ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["response.error"]},". ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["poll"]}," does this by default."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { BriaClient, BriaException } from \"@bria-ai/client\";\n\nconst client = new BriaClient();\n\ntry {\n  const response = await client.run(\"image/generate\", { prompt: \"a matte black travel mug\" }, { raiseForStatus: true });\n  console.log(response.result?.image_url);\n} catch (err) {\n  if (err instanceof BriaException) console.error(\"Bria API error:\", err.code, err.message, err.details);\n  else throw err;\n}\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Requests time out after 30 seconds by default (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestTimeout"]},", in seconds, on the constructor) and throw a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BriaException"]}," with code ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["408"]},". ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET"]}," requests, including polling, are retried on ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["429"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["502"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["503"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["504"]}," and on network errors (3 attempts with exponential backoff, honoring ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Retry-After"]},"). ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["run"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submit"]}," are never retried, so a job is never started twice; retry those yourself only when you know the submission did not go through."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"images-urls-files-bytes","__idx":6},"children":["Images: URLs, files, bytes"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Image"]}," turns any of these into the string the API expects, either the URL as-is or a raw base64 payload without the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["data:"]}," prefix:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { readFile } from \"node:fs/promises\";\nimport { Image } from \"@bria-ai/client\";\n\nnew Image(\"https://example.com/photo.jpg\").asBriaApiInput; // public URL, passed through\nnew Image(\"./photo.png\").asBriaApiInput; // local path, encoded to base64\nnew Image(await readFile(\"./photo.png\")).asBriaApiInput; // Buffer or Uint8Array\n(await Image.fromBlob(new Blob([await readFile(\"./photo.png\")]))).asBriaApiInput; // Blob, e.g. a browser File\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The client also drops ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["null"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["undefined"]}," values from payloads, so optional parameters can be left unset without being sent."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"webhooks","__idx":7},"children":["Webhooks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Instead of polling, ask Bria to POST the result to your server when the job completes. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["webhookUrl"]}," is an option of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["submit"]},", not part of the payload:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"const job = await client.submit(\n  \"image/generate\",\n  { prompt: \"a serene mountain landscape at dawn\" },\n  { webhookUrl: \"https://your-app.example.com/api/bria/webhook\" },\n);\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Verify every delivery with the bundled HMAC-SHA256 helper before acting on it:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { verifyWebhookSignature } from \"@bria-ai/client\";\n\n// Any framework: pass the raw request body and the three Bria-Webhook-* headers.\nfunction isValid(rawBody: string, headers: Record<string, string>): boolean {\n  return verifyWebhookSignature({\n    payload: rawBody,\n    webhookId: headers[\"bria-webhook-id\"] ?? \"\",\n    timestamp: headers[\"bria-webhook-timestamp\"] ?? \"\",\n    signatureHeader: headers[\"bria-webhook-signature\"] ?? \"\",\n    apiToken: process.env.BRIA_API_TOKEN ?? \"\",\n  });\n}\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["See ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/getting-started/async-requests#webhooks"},"children":["webhooks"]}," for the delivery contract, retries and a complete Express receiver."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"video-upload","__idx":8},"children":["Video upload"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Video endpoints take a hosted URL. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["client.upload()"]}," wraps the ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/local-video-upload-service"},"children":["Video Upload Service"]},": it requests a presigned upload, uploads the file, and returns a URL that stays valid for about 24 hours. Pass the file's MIME type; only ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["video/*"]}," types are accepted."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"const fileUrl = await client.upload(\"path/to/video.mp4\", \"video/mp4\");\n\nconst job = await client.submit(\"video/edit/remove_background\", { video: fileUrl });\nconst result = await client.poll(job, { interval: 5, timeout: 600 });\nconsole.log(result.result?.video_url);\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["upload"]}," also takes a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Buffer"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Uint8Array"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Blob"]}," instead of a path. Treat the returned URL as a secret: anyone holding it can download the file."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"batch-processing","__idx":9},"children":["Batch processing"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Submit everything first, then poll. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Promise.all"]}," runs the calls concurrently on one event loop:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { BriaClient, Image } from \"@bria-ai/client\";\n\nconst client = new BriaClient();\nconst paths = [\"sku-1.jpg\", \"sku-2.jpg\", \"sku-3.jpg\"];\n\nconst jobs = await Promise.all(\n  paths.map((p) => client.submit(\"image/edit/remove_background\", { image: new Image(p).asBriaApiInput })),\n);\nconst results = await Promise.all(jobs.map((job) => client.poll(job, { timeout: 120 })));\nfor (const [i, r] of results.entries()) console.log(paths[i], r.result?.image_url);\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Stay within your plan's ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/getting-started/rate-limits-and-errors"},"children":["rate limits"]},": cap how many jobs you submit at once."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"configuration-reference","__idx":10},"children":["Configuration reference"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Setting"},"children":["Setting"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Constructor option"},"children":["Constructor option"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Environment variable"},"children":["Environment variable"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Default"},"children":["Default"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["API token"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["apiToken"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BRIA_API_TOKEN"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["required"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Base URL"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["baseUrl"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BRIA_BASE_URL"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://engine.prod.bria-api.com"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Request timeout"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestTimeout"]}," (seconds)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["30"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Retries"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["retry"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{ total, backoffFactor }"]},")"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{ total: 3, backoffFactor: 2 }"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Extra headers"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["defaultHeaders"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["none"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Contributions and bug reports are welcome on ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/Bria-AI/bria-client/issues"},"children":["GitHub"]},"; the repository README covers the development setup."]}]},"headings":[{"value":"TypeScript SDK (@bria-ai/client)","id":"typescript-sdk-bria-aiclient","depth":1},{"value":"Install and authenticate","id":"install-and-authenticate","depth":2},{"value":"Your first call","id":"your-first-call","depth":2},{"value":"One client","id":"one-client","depth":2},{"value":"Three request methods","id":"three-request-methods","depth":2},{"value":"Responses and errors","id":"responses-and-errors","depth":2},{"value":"Images: URLs, files, bytes","id":"images-urls-files-bytes","depth":2},{"value":"Webhooks","id":"webhooks","depth":2},{"value":"Video upload","id":"video-upload","depth":2},{"value":"Batch processing","id":"batch-processing","depth":2},{"value":"Configuration reference","id":"configuration-reference","depth":2}],"frontmatter":{"title":"TypeScript SDK (@bria-ai/client)","description":"The official TypeScript and JavaScript client for the Bria API. One-call sync requests, async submit-and-poll, webhooks, local video upload and image helpers for Node.js.","seo":{"title":"TypeScript SDK (@bria-ai/client)"}},"lastModified":"2026-09-29T14:36:47.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/integration-methods/typescript-sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}