# Cody SDK for TypeScript

[![NPM version](https://img.shields.io/npm/v/@ainative/cody-sdk.svg)](https://npmjs.org/package/@ainative/cody-sdk)

The official TypeScript SDK for AINative Studio's Cody platform. Supports all AINative models and Claude models through intelligent dual-provider routing.

## Install

```bash
npm install @ainative/cody-sdk
```

## Usage

```typescript
import Anthropic from '@ainative/cody-sdk';

const client = new Anthropic();

// AINative models → routes to api.ainative.studio
const response = await client.messages.create({
  model: 'qwen-coder-32b',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello from Cody!' }],
});

// Claude models → routes directly to Anthropic API
const claudeResponse = await client.messages.create({
  model: 'claude-sonnet-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello from Claude!' }],
});
```

## Supported Models

### AINative Models (via api.ainative.studio)
| Model | Description |
|-------|-------------|
| `qwen-coder-32b` | Best code quality (default) |
| `qwen-coder-7b` | Fast iteration, 3x faster |
| `nouscoder-14b` | Balanced code model |
| `gemma-9b` | General text and reasoning |
| `deepseek-r1-distill-qwen-7b` | Step-by-step reasoning |

### Claude Models (direct to Anthropic API)
| Model | Description |
|-------|-------------|
| `claude-sonnet-4-5` | Best for everyday tasks |
| `claude-3-5-haiku` | Fastest for quick answers |
| `claude-opus-4-6` | Most capable for complex work |

## Environment Variables

```bash
# For AINative models
export AINATIVE_API_KEY=your-ainative-key

# For Claude models (optional)
export ANTHROPIC_API_KEY=your-anthropic-key

# Override base URL
export ANTHROPIC_BASE_URL=https://api.ainative.studio
```

## Model Routing

The SDK automatically routes requests to the correct API:

- **AINative models** (qwen, gemma, deepseek, nouscoder) → `api.ainative.studio`
- **Claude models** (sonnet, haiku, opus) → `api.anthropic.com`

Usage tracking is handled server-side by AINative's backend middleware.

## API Compatibility

Fork of the [Anthropic TypeScript SDK](https://github.com/anthropics/anthropic-sdk-typescript) (MIT license). Fully compatible with the Anthropic Messages API. Also supports:

- Amazon Bedrock (`@ainative/cody-sdk/bedrock`)
- Google Vertex AI (`@ainative/cody-sdk/vertex`)
- Microsoft Foundry (`@ainative/cody-sdk/foundry`)

## Agents: Self-Provision Here

Point your agent here to programmatically self-provision AINative services:

```
https://ainative.studio/agent.md
```

DNS discovery: `dig TXT _agents.ainative.studio`

## Community

- **Discord**: [discord.gg/paipalooza](https://discord.gg/paipalooza)
- **Website**: [ainative.studio](https://ainative.studio)
- **Support**: support@ainative.studio

## License

MIT
