Repository: vercel-labs/ai
File: packages/togetherai/src/togetherai-image-model.ts (TypeScript)

Code before:
    });

    // Handle image input from files
    let imageUrl: string | undefined;
    if (files != null && files.length > 0) {
      imageUrl = convertImageModelFileToDataUri(files[0]);

      if (files.length > 1) {
        warnings.push({
          type: 'other',
          message:
            'Together AI only supports a single input image. Additional images are ignored.',
        });
      }
    }

    const splitSize = size?.split('x');
    // https://docs.together.ai/reference/post_images-generations
    const { value: response, responseHeaders } = await postJsonToApi({
      url: `${this.config.baseURL}/images/generations`,
      headers: combineHeaders(this.config.headers(), headers),
      body: {
        model: this.modelId,
        prompt,
        seed,
        n,
        ...(splitSize && {
          width: parseInt(splitSize[0]),
          height: parseInt(splitSize[1]),
        }),
        ...(imageUrl != null ? { image_url: imageUrl } : {}),
        response_format: 'base64',
        ...(togetheraiOptions ?? {}),
      },
      failedResponseHandler: createJsonErrorResponseHandler({
        errorSchema: togetheraiErrorSchema,
        errorToMessage: data => data.error.message,
      }),
      successfulResponseHandler: createJsonResponseHandler(
        togetheraiImageResponseSchema,
      ),
      abortSignal,
      fetch: this.config.fetch,
    });

    return {
      images: response.data.map(item => item.b64_json),
      warnings,
      response: {
        timestamp: currentDate,
        modelId: this.modelId,

Review comment (suggestion):
please test a few other models and make sure they respond to absence of `n` by producing one (and not erroring)

Code after:
    });

    // Handle image input from files
    let imageUrl: string | undefined;
    if (files != null && files.length > 0) {
      imageUrl = convertImageModelFileToDataUri(files[0]);

      if (files.length > 1) {
        warnings.push({
          type: 'other',
          message:
            'Together AI only supports a single input image. Additional images are ignored.',
        });
      }
    }

    const splitSize = size?.split('x');
    // https://docs.together.ai/reference/post_images-generations
    const { value: response, responseHeaders } = await postJsonToApi({
      url: `${this.config.baseURL}/images/generations`,
      headers: combineHeaders(this.config.headers(), headers),
      body: {
        model: this.modelId,
        prompt,
        seed,
        ...(n > 1 ? { n } : {}),
        ...(splitSize && {
          width: parseInt(splitSize[0]),
          height: parseInt(splitSize[1]),
        }),
        ...(imageUrl != null ? { image_url: imageUrl } : {}),
        response_format: 'base64',
        ...(togetheraiOptions ?? {}),
      },
      failedResponseHandler: createJsonErrorResponseHandler({
        errorSchema: togetheraiErrorSchema,
        errorToMessage: data => data.error.message,
      }),
      successfulResponseHandler: createJsonResponseHandler(
        togetheraiImageResponseSchema,
      ),
      abortSignal,
      fetch: this.config.fetch,
    });

    return {
      images: response.data.map(item => item.b64_json),
      warnings,
      response: {
        timestamp: currentDate,
        modelId: this.modelId,