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

# Best Practices

> Recommended patterns and practices

## Cleanup Instances

```typescript theme={null}
const instance = await Instance.create({
  name: 'my-session',
  description: 'Session'
});

try {
  await instance.run('Task 1');
  await instance.run('Task 2');
} finally {
  await instance.destroy(); // Always cleanup
}
```

## Reuse Templates

```typescript theme={null}
const client = new In10ntClient();

// Check if template exists before creating
const templates = await client.templates.list();
let template = templates.find(t => t.name === 'python-ml');

if (!template) {
  template = await client.templates.create({
    name: 'python-ml',
    image: 'python:3.11-slim',
    registryType: 'dockerhub'
  });
  await template.waitUntilReady();
}
```

## Error Handling

```typescript theme={null}
import { Instance, In10ntError, TimeoutError, HealthCheckError } from '@in10nt/sdk';

try {
  await instance.run('Build something');
} catch (error) {
  if (error instanceof TimeoutError) {
    console.error('Task timed out');
  } else if (error instanceof HealthCheckError) {
    console.error('Instance not healthy');
  } else if (error instanceof In10ntError) {
    console.error(`API error (${error.statusCode}):`, error.message);
  }
}
```

## Use Environment Variables

```bash theme={null}
# .env
IN10NT_API_KEY=your_key
```

```typescript theme={null}
// Zero-config — reads IN10NT_API_KEY automatically
import { Instance } from '@in10nt/sdk';

const instance = await Instance.create({
  name: 'my-agent',
  description: 'Agent'
});
```

<Warning>
  Never commit `.env` to git. Add to `.gitignore`
</Warning>

## Cost Optimization

```typescript theme={null}
// Reuse one instance for multiple tasks
const instance = await Instance.create({
  name: 'session',
  description: 'Multi-task session'
});
await instance.run('Task 1');
await instance.run('Task 2');
await instance.run('Task 3');
await instance.destroy();
```

### Set Timeouts

```typescript theme={null}
await instance.run('Complex task', {
  timeout: 120_000  // 2 min max
});
```

### Monitor Usage

```typescript theme={null}
const client = new In10ntClient();
const usage = await client.usage.getTokenUsage();
if (usage.monthlyCost > 100) {
  console.warn('Cost threshold exceeded');
}
```

## Naming

```typescript theme={null}
// Clear names
'user-api-builder'
'python-ml-v2'
'discord-bot-prod'

// Avoid vague names
// 'inst1', 'tmpl', 'test'
```

## Performance

```typescript theme={null}
// Parallel creation (fast)
const [inst1, inst2, inst3] = await Promise.all([
  Instance.create({ name: 'agent-1', description: 'Agent 1' }),
  Instance.create({ name: 'agent-2', description: 'Agent 2' }),
  Instance.create({ name: 'agent-3', description: 'Agent 3' })
]);
```

## Logger

```typescript theme={null}
import { In10ntClient, createConsoleLogger } from '@in10nt/sdk';

// Opt-in to debug logging
const client = new In10ntClient({ logger: createConsoleLogger() });

// Or pass any logger with { debug, info, warn, error }
const client = new In10ntClient({ logger: myLogger });
```

## Security

* Never log API keys
* Use env vars for secrets
* Rotate keys regularly
* Separate dev/prod keys
