# SDK Configuration

This guide covers configuration for both Python and TypeScript SDKs, including basic setup, advanced options, and debugging capabilities.

## Getting Started

### Python SDK

The recommended approach to configuring the Python SDK is to use the `opik configure` command. This will prompt you to set up your API key and Opik instance URL (if applicable) to ensure proper routing and authentication. All details will be saved to a configuration file.

<Tabs>
  <Tab value="Opik Cloud" title="Opik Cloud">
    If you are using the Cloud version of the platform, you can configure the SDK by running:

    ```python
    import opik

    opik.configure(use_local=False)
    ```

    You can also configure the SDK by calling [`configure`](https://www.comet.com/docs/opik/python-sdk-reference/cli.html) from the Command line:

    ```bash
    opik configure
    ```
  </Tab>

  <Tab value="Self-hosting" title="Self-hosting">
    If you are self-hosting the platform, you can configure the SDK by running:

    ```python
    import opik

    opik.configure(use_local=True)
    ```

    or from the Command line:

    ```bash
    opik configure --use_local
    ```
  </Tab>
</Tabs>

The `configure` methods will prompt you for the necessary information and save it to a configuration file (`~/.opik.config`). When using the command line version, you can use the `-y` or `--yes` flag to automatically approve any confirmation prompts:

```bash
opik configure --yes
```

### TypeScript SDK

For the TypeScript SDK, configuration is done through environment variables, constructor options, or configuration files.

**Installation:**

```bash
npm install opik
```

**Basic Configuration:**

You can configure the Opik client using environment variables in a `.env` file:

```bash
OPIK_API_KEY="your-api-key"
OPIK_URL_OVERRIDE="https://www.comet.com/opik/api"
OPIK_PROJECT_NAME="your-project-name"
OPIK_WORKSPACE="your-workspace-name"
```

Or pass configuration directly to the constructor:

```typescript
import { Opik } from "opik";

const client = new Opik({
  apiKey: "<your-api-key>",
  apiUrl: "https://www.comet.com/opik/api",
  projectName: "<your-project-name>",
  workspaceName: "<your-workspace-name>",
});
```

## Configuration Methods

Both SDKs support multiple configuration approaches with different precedence orders.

### Configuration Precedence

**Python SDK:** Constructor options → Environment variables → Configuration file → Defaults

**TypeScript SDK:** Constructor options → Environment variables → Configuration file (`~/.opik.config`) → Defaults

### Environment Variables

Both SDKs support environment variables for configuration. Here's a comparison of available options:

| Configuration       | Python Env Variable          | TypeScript Env Variable | Description                                    |
| ------------------- | ---------------------------- | ----------------------- | ---------------------------------------------- |
| API Key             | `OPIK_API_KEY`               | `OPIK_API_KEY`          | API key for Opik Cloud                         |
| URL Override        | `OPIK_URL_OVERRIDE`          | `OPIK_URL_OVERRIDE`     | Opik server URL                                |
| Project Name        | `OPIK_PROJECT_NAME`          | `OPIK_PROJECT_NAME`     | Project name                                   |
| Workspace           | `OPIK_WORKSPACE`             | `OPIK_WORKSPACE`        | Workspace name                                 |
| Config Path         | `OPIK_CONFIG_PATH`           | `OPIK_CONFIG_PATH`      | Custom config file location                    |
| Track Disable       | `OPIK_TRACK_DISABLE`         | N/A                     | Disable tracking (Python only)                 |
| Flush Timeout       | `OPIK_DEFAULT_FLUSH_TIMEOUT` | N/A                     | Default flush timeout (Python only)            |
| TLS Certificate     | `OPIK_CHECK_TLS_CERTIFICATE` | N/A                     | Check TLS certificates (Python only)           |
| Batch Delay         | N/A                          | `OPIK_BATCH_DELAY_MS`   | Batching delay in ms (TypeScript only)         |
| Hold Until Flush    | N/A                          | `OPIK_HOLD_UNTIL_FLUSH` | Hold data until manual flush (TypeScript only) |
| Console Log Level   | `OPIK_CONSOLE_LOGGING_LEVEL` | N/A                     | Console log level (Python only)                |
| File Log Level      | `OPIK_FILE_LOGGING_LEVEL`    | N/A                     | File log level (Python only)                   |
| Optimizer Log Level | `OPIK_OPTIMIZER_LOG_LEVEL`   | N/A                     | Opik Optimizer SDK log level (Python only)     |
| Log Level           | N/A                          | `OPIK_LOG_LEVEL`        | Logging level (TypeScript only)                |

### Using .env Files

Both SDKs support `.env` files for managing environment variables. This is a good practice to avoid hardcoding secrets and to make your configuration more portable.

**For Python projects**, install `python-dotenv`:

```shell
pip install python-dotenv
```

**For TypeScript projects**, `dotenv` is automatically loaded by the SDK.

Create a `.env` file in your project's root directory:

```dotenv