> ## Documentation Index
> Fetch the complete documentation index at: https://docs.img-processing.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started

> Learn how to get started with the Image Processing SDK

## Overview

IMG Processing API SDK is a set of tools that allow you to interact with the IMG Processing API from your application.
The SDK provides three basic elements, the `IMGProcessingClient`, the `ImageObject`, and the `APIError` classes.

Soon we will talk more about each of these elements, but first, let's see how to install the SDK in your project.

## Available SDKs

Currently, the SDK is available for the following languages:

<CardGroup cols={1}>
  <Card horizontal title="Node.js" icon="node-js" href="https://github.com/img-processing/node-sdk">
    Node.js SDK for the IMG Processing API
  </Card>
</CardGroup>

## Installation

You can install the SDK using a package manager:

```bash node-sdk theme={null}
npm install img-processing-sdk
```

## Authentication

After installing the SDK, you need to authenticate your requests using your API key.
Check out the [Authentication](/api-reference/authentication) section for more information about how to get an API key.

After getting your API key, use it as an environment variable or application argument to
prevent hardcoding it in your code, and keep it secure.

## Using the SDK

To start using the SDK, you need to import the client and create an instance of it.

```typescript node-sdk theme={null}
import ImgProcessing from 'img-processing-sdk';

const client = new ImgProcessing({
  apiKey: process.env['IMG_PROCESSING_API_KEY'], // This is the default and can be omitted
});

const imageObject = await client.images.retrieve('image_etm0g3x5iap4cld1qcfsjvo2');

console.log(imageObject.id);
```

Width the client, you can interact with many functions, for example, let's upload an image:

```typescript node-sdk theme={null}
await client.images.upload({ image: fs.createReadStream('/path/to/file'), name: 'example-image' });
```

For each programming language, there are different approaches to using the SDK, but the general idea is the same.
You can check the API Reference of the SDK for more information on how to use it.

<CardGroup cols={1}>
  <Card horizontal title="Node.js" icon="node-js" href="https://github.com/img-processing/node-sdk#readme">
    Instructions on how to use the Node.js SDK
  </Card>
</CardGroup>

## Handling errors

When the library is unable to connect to the API,
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
a subclass of `APIError` will be thrown:

```typescript node-sdk theme={null}
const imageObject = await client.images.retrieve('image_etm0g3x5iap4cld1qcfsjvo2').catch(async (err) => {
  if (err instanceof ImgProcessing.APIError) {
    console.log(err.status); // 400
    console.log(err.name); // BadRequestError
    console.log(err.headers); // {server: 'nginx', ...}
  } else {
    throw err;
  }
});
```

Error codes are as follows:

| Status Code | Error Type                 |
| ----------- | -------------------------- |
| 400         | `BadRequestError`          |
| 401         | `AuthenticationError`      |
| 403         | `PermissionDeniedError`    |
| 404         | `NotFoundError`            |
| 422         | `UnprocessableEntityError` |
| 429         | `RateLimitError`           |
| >=500       | `InternalServerError`      |
| N/A         | `APIConnectionError`       |

## Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
429 Rate Limit, and >=500 Internal errors will all be retried by default.

You can use the `maxRetries` option to configure or disable this:

```typescript node-sdk theme={null}
// Configure the default for all requests:
const client = new ImgProcessing({
  maxRetries: 0, // default is 2
});

// Or, configure per-request:
await client.images.retrieve('image_etm0g3x5iap4cld1qcfsjvo2', {
  maxRetries: 5,
});
```

## Timeouts

Requests time out after 1 minute by default. You can configure this with a `timeout` option:

```typescript node-sdk theme={null}
// Configure the default for all requests:
const client = new ImgProcessing({
  timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

// Override per-request:
await client.images.retrieve('image_etm0g3x5iap4cld1qcfsjvo2', {
  timeout: 5 * 1000,
});
```

On timeout, an `APIConnectionTimeoutError` is thrown.

Note that requests which time out will be [retried twice by default](#retries).

## Billing

All the request to the API that return a 201 status code will be counted as a processed image.
There are some endpoints that could be counted as multiple images processed, since they
execute two or more operations, in that case,
the docs will specify how many images will be counted for that operation.

Test images are not counted in the billing.

## Support

If you encounter any issues or have questions about using the Image Processing API, please don't hesitate to browse the API Reference for detailed information on each endpoint,
or contact our support team for personalized assistance.

We're excited to see what you'll create with the Image Processing API. Happy coding!
