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

# Installation

> Install and configure the S4Kit SDK

## Installation

Install the S4Kit SDK using your preferred package manager:

<CodeGroup>
  ```bash npm theme={null}
  npm install s4kit
  ```

  ```bash yarn theme={null}
  yarn add s4kit
  ```

  ```bash pnpm theme={null}
  pnpm add s4kit
  ```

  ```bash bun theme={null}
  bun add s4kit
  ```
</CodeGroup>

## Configuration

Create an S4Kit client instance with your configuration:

```typescript theme={null}
import { S4Kit } from 's4kit';

const client = new S4Kit({
  apiKey: 'sk_live_...',        // Required: Your API key
  connection: 'production',        // Optional: Default SAP instance
  baseUrl: 'https://api.s4kit.com', // Optional: Custom API URL
  service: 'API_BUSINESS_PARTNER' // Optional: Default OData service
});
```

### Configuration Options

| Option       | Type     | Required | Description                                               |
| ------------ | -------- | -------- | --------------------------------------------------------- |
| `apiKey`     | `string` | Yes      | Your S4Kit API key (starts with `sk_live_` or `sk_test_`) |
| `connection` | `string` | No       | Default SAP instance alias to use for requests            |
| `baseUrl`    | `string` | No       | Custom API URL (default: `https://api.s4kit.com`)         |
| `service`    | `string` | No       | Default OData service name                                |

## Environment Variables

We recommend storing your API key in environment variables:

```typescript theme={null}
const client = new S4Kit({
  apiKey: process.env.S4KIT_API_KEY,
  connection: process.env.S4KIT_CONNECTION
});
```

<Warning>
  Never commit API keys to source control. Use `.env` files or secrets management.
</Warning>

### Example `.env` File

```env theme={null}
S4KIT_API_KEY=sk_live_abc123...
S4KIT_CONNECTION=production
```

## TypeScript Support

The SDK is written in TypeScript and provides full type definitions out of the box:

```typescript theme={null}
import { S4Kit, S4KitConfig, QueryOptions } from 's4kit';

const config: S4KitConfig = {
  apiKey: process.env.S4KIT_API_KEY!,
  connection: 'production'
};

const client = new S4Kit(config);
```

## Generated Types

For full type safety with your SAP entities, use the CLI to generate types from OData metadata:

```bash theme={null}
npx s4kit generate-types --api-key sk_live_... --output ./types
```

Then use the types in your code:

```typescript theme={null}
import type { A_BusinessPartner } from './types/sap';

const partners = await client.A_BusinessPartner.list() as A_BusinessPartner[];
```

<Info>
  See the [CLI documentation](/sdk/cli) for more information on type generation.
</Info>

## Multiple Clients

You can create multiple client instances for different environments:

```typescript theme={null}
const prodClient = new S4Kit({
  apiKey: process.env.S4KIT_API_KEY,
  connection: 'production'
});

const devClient = new S4Kit({
  apiKey: process.env.S4KIT_API_KEY,
  connection: 'dev'
});
```

Or override the connection per-request:

```typescript theme={null}
// Use production connection
const prodOrders = await client.A_SalesOrder.list({
  connection: 'production'
});

// Use development connection
const devOrders = await client.A_SalesOrder.list({
  connection: 'dev'
});
```
