Skip to content

fix(image-gen): resolve relative URLs returned by Xinference and compatible backends#1506

Merged
MODSetter merged 1 commit into
MODSetter:devfrom
okxint:fix/xinference-relative-image-url
Jun 17, 2026
Merged

fix(image-gen): resolve relative URLs returned by Xinference and compatible backends#1506
MODSetter merged 1 commit into
MODSetter:devfrom
okxint:fix/xinference-relative-image-url

Conversation

@okxint

@okxint okxint commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

When using an OpenAI-compatible image backend like Xinference, the API can return a relative URL like /files/image.png instead of an absolute one. The browser can't resolve this, so generated images fail to display.

Root cause: generate_image.py passed data[0].url directly to the frontend without checking whether it was absolute. Xinference's file-serving endpoint returns a path-only URL.

Fix: After resolving the model config via to_litellm(), we now capture api_base. When the returned URL starts with /, we extract the origin (scheme + host + port) from api_base and prepend it to produce a fully-qualified URL. Absolute URLs (OpenAI, Azure, Recraft, etc.) are passed through unchanged.

No behaviour change for providers that already return absolute URLs.

Closes #1496

High-level PR Summary

This PR fixes an issue where OpenAI-compatible image generation backends like Xinference return relative URLs (e.g., /files/image.png) instead of absolute URLs, causing images to fail to display in the browser. The fix captures the api_base from the resolved model configuration and prepends the provider's origin (scheme + host + port) to relative URLs, while leaving absolute URLs unchanged. This ensures all image URLs are fully-qualified and browser-resolvable.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/agents/chat/multi_agent_chat/subagents/builtins/deliverables/tools/generate_image.py

Need help? Join our Discord

…atible backends

Some OpenAI-compatible image backends (e.g. Xinference) return a relative
URL like /files/image.png in data[0].url instead of an absolute one.
Browsers cannot resolve these, causing images to fail to load.

Track the provider's api_base after resolving model config via to_litellm().
When the returned URL starts with "/", extract the origin (scheme + host + port)
from api_base and prepend it to produce a full absolute URL.

No behaviour change for providers that return absolute URLs (OpenAI, Azure, etc).

Closes MODSetter#1496
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

@okxint is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5032b45c-8758-4461-a663-7a883d1a3604

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MODSetter MODSetter merged commit f75878f into MODSetter:dev Jun 17, 2026
6 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants