> For the complete documentation index, see [llms.txt](https://globalmoo.gitbook.io/globalmoo-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://globalmoo.gitbook.io/globalmoo-documentation/core/sdk_initialization.md).

# SDK Initialization

This guide covers how to properly initialize and configure the globalMOO SDKs.

## Client Initialization

Each SDK provides a Client class for API interaction:

{% tabs %}
{% tab title="Python" %}

```python
from globalmoo.client import Client
from globalmoo.credentials import Credentials

# Method 1: Environment Variables
client = Client()  # Uses GMOO_API_KEY and GMOO_API_URI

# Method 2: Direct Credentials
credentials = Credentials(
    api_key="your-api-key",
    base_uri="https://app.globalmoo.com/api/"
)
client = Client(credentials=credentials)

# Method 3: Custom HTTP Client
import httpx
http_client = httpx.Client(
    timeout=30.0,
    headers={"Custom-Header": "value"}
)
client = Client(credentials=credentials, http_client=http_client)
```

{% endtab %}

{% tab title="PHP" %}

```php
use GlobalMoo\Client;
use GlobalMoo\Credentials;

// Method 1: Environment Variables
$client = new Client();

// Method 2: Direct Credentials
$credentials = new Credentials(
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/"
);
$client = new Client($credentials);

// Method 3: Custom HTTP Client
use Symfony\Component\HttpClient\HttpClient;
$httpClient = HttpClient::create([
    'timeout' => 30.0,
    'headers' => ['Custom-Header' => 'value']
]);
$client = new Client($credentials, $httpClient);
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { Client } = require('globalmoo');

// Method 1: Environment Variables
const client = new Client();

// Method 2: Direct Configuration
const client = new Client({
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/"
});

// Method 3: Custom Configuration
const client = new Client({
    apiKey: "your-api-key",
    baseUri: "https://app.globalmoo.com/api/",
    timeout: 30000,
    headers: { "Custom-Header": "value" }
});
```

{% endtab %}
{% endtabs %}

## Environment Variables

The SDKs support these environment variables:

| Variable       | Required | Description                                                 |
| -------------- | -------- | ----------------------------------------------------------- |
| GMOO\_API\_KEY | Yes      | Your API key for authentication                             |
| GMOO\_API\_URI | No       | API base URI (defaults to <https://app.globalmoo.com/api/>) |

## Debug Mode

Enable debug mode for detailed logging:

{% tabs %}
{% tab title="Python" %}

```python
import logging
logging.basicConfig(level=logging.DEBUG)
client = Client(debug=True)
```

{% endtab %}

{% tab title="PHP" %}

```php
// Set debug flag in constructor
$client = new Client(debug: true);

// Configure logging
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('globalmoo');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const client = new Client({
    debug: true,
    logger: console
});
```

{% endtab %}
{% endtabs %}

## HTTP Client Configuration

The SDKs use different HTTP clients:

* Python: httpx
* PHP: Symfony HttpClient
* Node.js: node-fetch

Custom configuration options:

| Option  | Default     | Description                |
| ------- | ----------- | -------------------------- |
| timeout | 30.0        | Request timeout in seconds |
| retries | 3           | Number of retry attempts   |
| backoff | exponential | Retry backoff strategy     |
| headers | {}          | Custom HTTP headers        |

## Best Practices

1. Use environment variables for credentials
2. Enable debug mode during development
3. Configure appropriate timeouts
4. Handle client cleanup (Python/PHP)
5. Set custom headers when needed
6. Use typed inputs where available
7. Configure logging appropriately

## Client Lifecycle

```python
# Python example
with Client() as client:
    # Client automatically closes
    result = client.create_model(...)

# Manual cleanup
client = Client()
try:
    result = client.create_model(...)
finally:
    client.http_client.close()
```

## Production Configuration

For production environments:

1. Set appropriate timeouts
2. Configure retry strategies
3. Use secure credential storage
4. Monitor API rate limits
5. Handle cleanup properly
6. Log errors appropriately
7. Use separate API keys
