HeyPuter/puter · warning · HttpError

bad_request

bad_request

Error message

`prompt` must be a non-empty string

What it means

The Together AI image provider rejects calls where the prompt parameter is not a non-empty string. This check (line 85) runs after the test_mode short-circuit, so it applies to all real generation requests. The validation ensures the upstream Together API receives a usable text prompt.

Source

Thrown at src/backend/drivers/ai-image/providers/together/TogetherImageProvider.ts:86

    }

    getDefaultModel(): string {
        return DEFAULT_MODEL;
    }

    async generate(params: IGenerateParams): Promise<string> {
        const { prompt, test_mode } = params;
        let { model, ratio, quality } = params;
        const options = params as TogetherGenerateParams;

        const selectedModel = this.#getModel(model);

        if (test_mode) {
            return 'https://puter-sample-data.puter.site/image_example.png';
        }

        if (typeof prompt !== 'string' || prompt.trim().length === 0) {
            throw new HttpError(400, '`prompt` must be a non-empty string', {
                legacyCode: 'bad_request',
            });
        }

        // Canonical `input_images` → Together's native fields. Together accepts
        // a single input image: a URL goes to `image_url`, base64/data-URI to
        // `image_base64` (via the existing `input_image` alias).
        const singleInput = resolveSingleInputImage(params, 'Together AI');
        if (singleInput) {
            if (isHttpUrl(singleInput)) {
                options.image_url ??= singleInput;
            } else {
                options.input_image ??= singleInput;
            }
        }

        ratio = ratio || TOGETHER_DEFAULT_RATIO;

View on GitHub (pinned to 908ec23eda)

Solutions

  1. Ensure the prompt parameter is a non-empty, non-whitespace string before calling generate().
  2. Validate user input on the client side and show an error message before making the API call.
  3. Use a default prompt or reject the request early if the prompt is missing.

Example fix

// before
const result = await provider.generate({ prompt: userPrompt }); // userPrompt may be ''

// after
if (!userPrompt || typeof userPrompt !== 'string' || !userPrompt.trim()) {
  throw new Error('Prompt is required');
}
const result = await provider.generate({ prompt: userPrompt.trim() });
Defensive patterns

Strategy: validation

Validate before calling

function validatePrompt(prompt: unknown): string {
  if (typeof prompt !== 'string' || prompt.trim().length === 0) {
    throw new Error('prompt must be a non-empty string');
  }
  return prompt.trim();
}
// Use before calling generate:
const cleanPrompt = validatePrompt(params.prompt);

Type guard

function isValidPrompt(value: unknown): value is string {
  return typeof value === 'string' && value.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling generate() with prompt set to undefined, null, an empty string, a whitespace-only string, or a non-string type (number, object). This can happen if the caller passes a falsy prompt or the prompt field is accidentally omitted from the params object.

Common situations: Calling the image generation API with an empty or undefined prompt variable; form submission where the prompt field was left blank; programmatic calls where the prompt is conditionally set but the condition evaluated to a falsy value.

Related errors


AI-assisted analysis of HeyPuter/puter@908ec23eda (2026-08-12). Data as JSON: /api/errors/e6ac66d46230f6c2. Report an issue: GitHub.