danny-avila/LibreChat · error · Error

This tool is only available for agents.

Error message

This tool is only available for agents.

What it means

Construction-time guard in createOpenAIImageTools: the OpenAI image generate/edit tools are agent-only. If `fields.override` is false AND `fields.isAgent` is not truthy, the factory throws before building any tool. Mirrors the same pattern used by GeminiImageGen.

Source

Thrown at api/app/clients/tools/structured/OpenAIImageTools.js:68

/**
 * Creates OpenAI Image tools (generation and editing)
 * @param {Object} fields - Configuration fields
 * @param {ServerRequest} fields.req - Whether the tool is being used in an agent context
 * @param {boolean} fields.isAgent - Whether the tool is being used in an agent context
 * @param {string} fields.IMAGE_GEN_OAI_API_KEY - The OpenAI API key
 * @param {boolean} [fields.override] - Whether to override the API key check, necessary for app initialization
 * @param {MongoFile[]} [fields.imageFiles] - The images to be used for editing
 * @param {string} [fields.imageOutputType] - The image output type configuration
 * @param {string} [fields.fileStrategy] - The file storage strategy
 * @returns {Array<ReturnType<tool>>} - Array of image tools
 */
function createOpenAIImageTools(fields = {}) {
  /** @type {boolean} Used to initialize the Tool without necessary variables. */
  const override = fields.override ?? false;
  /** @type {boolean} */
  if (!override && !fields.isAgent) {
    throw new Error('This tool is only available for agents.');
  }
  const { req } = fields;
  const imageOutputType = fields.imageOutputType || EImageOutputType.PNG;
  const appFileStrategy = fields.fileStrategy;

  const getApiKey = () => {
    const apiKey = process.env.IMAGE_GEN_OAI_API_KEY ?? '';
    if (!apiKey && !override) {
      throw new Error('Missing IMAGE_GEN_OAI_API_KEY environment variable.');
    }
    return apiKey;
  };

  let apiKey = fields.IMAGE_GEN_OAI_API_KEY ?? getApiKey();
  const closureConfig = { apiKey };

  const imageModel = process.env.IMAGE_GEN_OAI_MODEL || 'gpt-image-1';

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Construct the tools only from the agent tool-loading path, which sets `isAgent: true`.
  2. For app initialization / manifest loading, pass `override: true`.
  3. Use the dedicated non-agent image-generation endpoint for non-agent flows instead of these tools.
  4. Audit field forwarding at the call site to ensure isAgent is preserved.

Example fix

// before
const tools = createOpenAIImageTools({ req }); // throws

// after
const tools = createOpenAIImageTools({ req, isAgent: true });
// or bootstrap:
const tools = createOpenAIImageTools({ override: true });
Defensive patterns

Strategy: validation

Validate before calling

function assertAgentFactory(fields = {}) {
  if (!fields.override && !fields.isAgent) {
    throw new Error('createOpenAIImageTools requires isAgent:true (or override:true for bootstrap).');
  }
}

Type guard

function isAgentFactoryCall(fields) {
  return Boolean(fields?.override || fields?.isAgent);
}

Prevention

When it happens

Trigger: Calling createOpenAIImageTools() from a non-agent code path that forwards fields without `isAgent: true` and is not a manifest/bootstrap call (where override:true is used).

Common situations: Wiring OpenAI image tools into a legacy/assistant flow; a refactor that dropped isAgent when forwarding fields; a custom route that builds tools outside the agent controller; unit tests that call the factory without setting either flag.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/359c22b7caaa7a27. Report an issue: GitHub.