{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Self-Hosting Best Practices","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","whats-new/fibo-2.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 2.","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":"Ads","description":"Finished ads as input. Ad Delayer turns one into editable layers (the guide holds the layer document contract); Ad Resize produces it at other sizes with the layout redone.","includeFiles":["ads-overview.md","ads.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":"Self-hosting","description":"Run licensed Bria models on your own GPUs. Buy a per-model license, install with Bria Studio or the Python library, run, and handle license errors.","includeFiles":["self-hosted/quickstart.md","self-hosted/overview.md","self-hosted/best-practices.md","self-hosted/fibo-2.md","self-hosted/rmbg-2.md"]},{"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":"self-hosting-best-practices","__idx":0},"children":["Self-Hosting Best Practices"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Patterns for running a licensed Bria model in production. The examples use ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/self-hosted/rmbg-2"},"children":["RMBG 2.0"]},"; the same shape applies to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/self-hosted/fibo-2"},"children":["Fibo 2"]}," and any other self-hosted model."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"the-big-picture-treat-the-model-as-a-long-lived-service","__idx":1},"children":["The Big Picture: Treat the Model as a Long-Lived Service"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A self-hosted model is a service you start once and keep warm, not a function you call cold. Think in four stages:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Start"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]}," downloads the weights (first run) and loads the model onto the GPU."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Warm up"]}," — one throwaway inference so the first real request isn't the slow one."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Serve"]}," — reuse the pipeline for every request."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Stop"]}," — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["cleanup()"]}," on shutdown to free the GPU."]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"setup() is the expensive step"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]}," downloads weights and loads the model to the GPU. Run it once at startup and reuse the pipeline — never call it per request."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import os\nfrom remove_bg import RemoveBG, RemoveBGConfig, RemoveBGInput\n\n# Start: once at import/startup.\n_pipe = RemoveBG(config=RemoveBGConfig(compile_model=False, api_token=os.environ[\"BRIA_API_TOKEN\"]))\n_pipe.setup()\n# Warm up.\n_pipe.execute([RemoveBGInput(image=\"https://bria-test-images.s3.us-east-1.amazonaws.com/strawberry.jpg\")])\n\ndef remove_background(image):\n    # Serve: reuses the already-loaded model.\n    return _pipe.execute([RemoveBGInput(image=image)])[0].image\n\n# Stop: _pipe.cleanup() on shutdown.\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: Why does loading once matter so much?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Loading the model is seconds-to-minutes of GPU work, and the weights are large (Fibo 2 is about 26 GB). A service that calls ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]}," per request re-pays that cost every time and can exhaust GPU memory. Load once, hold the pipeline, and reuse ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["execute()"]},"."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"weights-and-startup","__idx":2},"children":["Weights and Startup"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Weights download once into ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BRIA_HOME"]}," (default ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["~/.bria/models"]},") and are reused on later runs. Persist that directory so a restart or a new container doesn't re-download them."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"docker run --gpus all \\\n  -e BRIA_API_TOKEN \\\n  -v bria-weights:/root/.bria \\\n  your-image\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: How do I avoid re-downloading 26 GB on every deploy?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Mount a persistent volume at ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["~/.bria"]}," (as above), or bake the weights into your image after a first ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]},". For many replicas, point them all at the same cached weights — a shared read-only volume works well."]}]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: How do I make the first request fast?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The first inference after ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]}," is slower (CUDA graphs, caches warming). Run one throwaway call at startup, as in the service example above, so a real user never hits the cold path."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"licensing-and-reliability","__idx":3},"children":["Licensing and Reliability"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The model checks your entitlement when it starts. A cancelled or ended license makes ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["setup()"]}," raise ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["LicenseError"]},"; a card retry (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["past_due"]},") stays active."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"from common.outpost import LicenseError\n\ntry:\n    _pipe.setup()\nexcept LicenseError as e:\n    # e.url links to the Licenses tab. Page a human and stop.\n    raise RuntimeError(f\"Self-hosted license problem: {e}. Renew at {e.url}\") from e\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"default","name":"A restart applies a renewal"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A long-running process keeps serving after a license lapses until its next restart — so a restart is also how you ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["apply"]}," a renewal. Keep a model restart in your runbook."]}]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: Should I auto-retry on a license error?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["No. A ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["LicenseError"]}," won't clear by retrying — it needs the license renewed on the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://platform.bria.ai/organization-management/licensing"},"children":["Licenses tab"]},". Alert instead of looping, and surface ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["e.url"]}," so whoever responds lands on the right page."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"versions-and-secrets","__idx":4},"children":["Versions and Secrets"]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: Should I pin the package version?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Install a floor during setup (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["remove_bg",">","=0.5.0"]},"), but pin an exact version in production and upgrade deliberately — a new package can change behavior. Model-version upgrades are sold separately from package updates, so pinning also keeps the model version stable."]},{"$$mdtype":"Tag","name":"pre","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["pip install \"remove_bg==0.5.0\" --extra-index-url \"","<","registry-url-from-the-console",">","\""]}]}]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: How do I handle ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["BRIA_API_TOKEN"]}," safely?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pass it as an environment variable or secret at runtime — never bake it into an image, commit it, or log it. Rotate keys on the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://platform.bria.ai/organization-management/api-keys"},"children":["API keys page"]},"; any active key of the organization works. In a Dockerfile, use a build-time ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ARG"]}," only to install the package (see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/self-hosted/rmbg-2#2-install"},"children":["RMBG manual install"]},"), and provide the token at runtime for the model itself."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"networking-and-attribution","__idx":5},"children":["Networking and Attribution"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Self-hosted models keep your images local, but the process still talks to Bria."]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: What outbound access does a self-hosted model need?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["On a restricted network, allow outbound HTTPS to:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["the Bria ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Engine"]}," (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["engine.prod.bria-api.com"]},") — license checks and the registry credential exchange"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["AWS CodeArtifact"]}," and Bria's ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["weights CDN"]}," — installing the package and downloading weights"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["attribution"]}," endpoint — the per-run vector that keeps outputs licensed"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["for Fibo 2 only, ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Google Vertex AI"]}," — prompt expansion runs on your own Vertex project"]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"default","name":"Keep attribution on"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Every generation sends a small, irreversible ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/enterprise/attribution"},"children":["attribution"]}," vector to Bria — never your images. It is what keeps your outputs covered by Bria's licensing terms, and what records your usage. Don't disable it."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"usage-and-scaling","__idx":6},"children":["Usage and Scaling"]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: How do I keep an eye on usage and overage?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Self-hosted runs show in ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Usage ","&"," billing"]}," in the Console, tagged as self-hosted, and count against your plan. Calls above the plan are billed, never blocked — watch the trend and ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://platform.bria.ai/organization-management/licensing"},"children":["upgrade"]}," (Starter → Scale) before overage adds up."]}]},{"$$mdtype":"Tag","name":"details","attributes":{},"children":[{"$$mdtype":"Tag","name":"summary","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Q: How do I run multiple replicas?"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Give each replica its own GPU and let each load the model once at startup. Point them all at a shared weights cache (a read-only ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["~/.bria"]}," volume, or weights baked into the image) so only the first download pays the full cost."]}]}]},"headings":[{"value":"Self-Hosting Best Practices","id":"self-hosting-best-practices","depth":1},{"value":"The Big Picture: Treat the Model as a Long-Lived Service","id":"the-big-picture-treat-the-model-as-a-long-lived-service","depth":2},{"value":"Weights and Startup","id":"weights-and-startup","depth":2},{"value":"Licensing and Reliability","id":"licensing-and-reliability","depth":2},{"value":"Versions and Secrets","id":"versions-and-secrets","depth":2},{"value":"Networking and Attribution","id":"networking-and-attribution","depth":2},{"value":"Usage and Scaling","id":"usage-and-scaling","depth":2}],"frontmatter":{"title":"Self-hosting best practices","description":"Run self-hosted Bria models reliably in production — treat the model as a long-lived service, cache weights, keep your license active, pin versions, and allow the right network egress.","seo":{"title":"Self-Hosting Best Practices"}},"lastModified":"2026-10-20T15:06:45.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/self-hosted/best-practices","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}