janhq/jan · error

No running MLX session found for model

Error message

No running MLX session found for model: ${modelId}

What it means

Thrown when the MLX plugin command plugin:mlx|find_mlx_session_by_model returns null for the given modelId, so there is no running MLX server session to derive a base URL (localhost port) and auth headers from. The client cannot talk to the model server without that session info.

Solutions

  1. Start the MLX session for this model before sending requests.
  2. Re-select the correct model id that matches the running session.
  3. Check the MLX server didn't crash (logs) and restart it, then retry.

Example fix

// before
const client = await createMlxClient('mlx-community/Llama-3-8B')
// after
const session = await invoke('plugin:mlx|find_mlx_session_by_model', { modelId })
if (!session) await invoke('plugin:mlx|start_mlx_session', { modelId })
const client = await createMlxClient(modelId)
Defensive patterns

Strategy: try-catch

Validate before calling

const session = await invoke('plugin:mlx|find_mlx_session_by_model', { modelId })
if (!session) await invoke('plugin:mlx|start_mlx_session', { modelId })

Type guard

const isMlxSession = (s) => !!s && typeof s.port === 'number'

Try / catch

try { return await createMlxClient(modelId) } catch (e) { if (e.message.startsWith('No running MLX session')) { await startMlxSession(modelId); return createMlxClient(modelId) } throw e }

Prevention

When it happens

Trigger: Requesting an MLX model that was never loaded; the MLX session terminated (crash, OOM, manual stop); modelId typo or stale reference after re-download; Tauri backend restarted without relaunching the session.

Common situations: Selecting an MLX model in chat without starting it; macOS app sleep/quit ending the server; switching branches or model versions so the id no longer matches the running session.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/5530948fcdece88d. Report an issue: GitHub.

Appendix: source

Thrown at web-app/src/lib/model-factory.ts:1105

        const serviceHub = useServiceStore.getState().serviceHub

        if (serviceHub) {
          await serviceHub.models().startModel(provider, modelId)
        }
      } catch (error) {
        console.error('Failed to start MLX model:', error)
        throw engineFailure('model-errors:startModelFailed', error)
      }
    }

    // Get session info which includes port and api_key
    const sessionInfo = await invoke<SessionInfo | null>(
      'plugin:mlx|find_mlx_session_by_model',
      { modelId }
    )

    if (!sessionInfo) {
      throw new Error(`No running MLX session found for model: ${modelId}`)
    }

    const baseUrl = `http://localhost:${sessionInfo.port}`
    const authHeaders = {
      Authorization: `Bearer ${sessionInfo.api_key}`,
      Origin: 'tauri://localhost',
    }

    // Share the common fetch (param normalisation + error-body cleaning that
    // rebuilds upstream errors from buffered text rather than re-decoding the
    // raw stream) with every other provider, then layer MLX's /cancel-on-abort
    // on top.
    let baseCustomFetch = createCustomFetch(
      httpFetch,
      parameters,
      false,
      undefined,
      true

View on GitHub (pinned to 7205d770c1)