CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tinify

Node.js client for the Tinify API that intelligently compresses, resizes, converts, and stores images in AVIF, WebP, JPEG, and PNG formats.

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration and Authentication

Configuration settings for the Tinify client including API key authentication, proxy settings, and application identification.

Capabilities

API Key Authentication

Set your Tinify API key for authentication. This is required before using any image processing functionality.

/**
 * Set the API key for authentication with the Tinify API
 * @example tinify.key = "your-api-key-here"
 */
let key: string;

Usage Example:

const tinify = require("tinify");

// Set API key (required)
tinify.key = "your-api-key-here";

// Now you can use image processing methods
await tinify.fromFile("image.png").toFile("compressed.png");

Application Identifier

Set an application identifier to be included in the user agent string for API requests.

/**
 * Set application identifier for user agent string
 * @example tinify.appIdentifier = "MyApp/1.0"
 */
let appIdentifier: string;

Usage Example:

const tinify = require("tinify");

tinify.key = "your-api-key";
tinify.appIdentifier = "MyApp/1.0";
// User agent will include: "Tinify/1.8.1 Node/v14.15.0 (linux) MyApp/1.0"

Proxy Configuration

Configure proxy settings for API requests when operating behind a corporate proxy.

/**
 * Set proxy URL for API requests
 * @example tinify.proxy = "http://proxy.example.com:8080"
 */
let proxy: string;

Usage Example:

const tinify = require("tinify");

tinify.key = "your-api-key";
tinify.proxy = "http://proxy.example.com:8080";

Compression Count

Read-only property that tracks the number of compressions made with your API key this month.

/**
 * Current compression count from API headers (read-only)
 * Updated automatically after each API request
 */
let compressionCount?: number;

Usage Example:

const tinify = require("tinify");

tinify.key = "your-api-key";

await tinify.fromFile("image.png").toFile("compressed.png");

console.log(`Compressions used: ${tinify.compressionCount}`);

API Key Validation

Validate your API key without performing actual image compression.

/**
 * Validate API key without performing compression
 * @returns Promise that resolves if key is valid, rejects on error
 */
function validate(): Promise<void>;

/**
 * Validate API key with callback support
 * @param callback - Callback function receiving error or null
 */
function validate(callback: (err: Error | null) => void): void;

Usage Examples:

const tinify = require("tinify");

tinify.key = "your-api-key";

// Promise-based validation
try {
  await tinify.validate();
  console.log("API key is valid");
} catch (error) {
  console.error("Invalid API key:", error.message);
}

// Callback-based validation
tinify.validate((err) => {
  if (err) {
    console.error("Invalid API key:", err.message);
  } else {
    console.log("API key is valid");
  }
});

Error Handling

Configuration methods can throw the following errors:

  • AccountError: Invalid API key, exceeded monthly limit, or billing issues
  • ConnectionError: Network connectivity problems
  • ClientError: Invalid proxy URL or malformed requests

Install with Tessl CLI

npx tessl i tessl/npm-tinify

docs

cloud-storage.md

configuration.md

error-handling.md

image-sources.md

index.md

results.md

transformations.md

tile.json