Skip to content

Why does calling AISwapLab directly from my browser fail with a CORS error?

AISwapLab's developer API is intended for server-side calls and does not enable browser CORS. Put the bearer key in your backend and have the browser call your own authenticated application route. Disabling browser protections or publishing the secret in frontend code is not a suitable integration fix.

PROTECT KEYS AND ACCOUNT ACCESSAISwapLab team · Editorial methodPublished 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Move the provider call; Add application ownership checks; Test both paths.
Workflow diagram: Move the provider call → Add application ownership checks → Test both paths. Read the article for evidence and limits.

CORS and user authorization are different controls

A browser refusal does not prove the API key is wrong or the model is offline. It can mean the request architecture is inappropriate for a private account credential. A backend proxy must still restrict who can submit tasks, which model and cost they may approve, and who may retrieve each output.

What to do next

  1. 01

    Move the provider call

    Create a server-only route in your application that loads the credential privately. Do not accept a free-form upstream URL or forward arbitrary browser headers.

  2. 02

    Add application ownership checks

    Authenticate your own user and load their approved internal task. Persist the returned AISwapLab job ID against that user before allowing status or download access.

  3. 03

    Test both paths

    Verify the backend's read-only /models connection first, then test the browser-to-your-backend request using fixtures for generation states. Remove the exposed key from any earlier client build.

A concrete example

Illustrative design: a web page calls /api/my-generation on its own site. That route validates the signed-in user and approved credit ceiling, then calls AISwapLab server-side. The browser receives a safe task status rather than the account credential.

Before you call it ready

  • The secret stays server-side.
  • The proxy is authenticated and constrained.
  • No browser security setting is weakened.

When to stop or choose another method

If a third-party widget requires a permanent account key in browser JavaScript, do not integrate it unchanged. Choose a server-side adapter or a different supported architecture.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation