# Quickstart
Source: https://docs.tensormachine.ai/quickstart

## Prerequisites

You need a Tensor Machine API key. Get one free at [tensormachine.ai](https://tensormachine.ai).

---

## Python

Install the OpenAI SDK — Tensor Machine is fully OpenAI-compatible:

```bash
pip install openai
```

```python
from openai import OpenAI

client = OpenAI(
    api_key="tx_live_...",         # your Tensor Machine API key
    base_url="https://edge.tensormachine.ai/v1",
)

response = client.chat.completions.create(
    model="z-ai/glm-5.2",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant for Indian enterprises."
        },
        {
            "role": "user",
            "content": "Summarise the DPDP Act 2023 in three bullet points."
        }
    ],
    max_tokens=256,
)

print(response.choices[0].message.content)
```

### Streaming (Python)

```python
stream = client.chat.completions.create(
    model="z-ai/glm-5.2",
    messages=[{"role": "user", "content": "Tell me about India's AI ecosystem."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

---

## Node.js / TypeScript

```bash
npm install openai
```

```typescript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.TENSORMACHINE_API_KEY,
  baseURL: 'https://edge.tensormachine.ai/v1',
});

async function main() {
  const response = await client.chat.completions.create({
    model: 'minimax/minimax-m3',
    messages: [
      { role: 'user', content: 'What are the top 5 AI use cases for Indian banks?' }
    ],
  });

  console.log(response.choices[0].message.content);
}

main();
```

### Streaming (Node.js)

```typescript
const stream = await client.chat.completions.create({
  model: 'minimax/minimax-m3',
  messages: [{ role: 'user', content: 'Explain GST filing in simple terms.' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```

---

## cURL

```bash
curl https://edge.tensormachine.ai/v1/chat/completions \
  -H "Authorization: Bearer $TENSORMACHINE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "z-ai/glm-5.2",
    "messages": [
      { "role": "user", "content": "Hello from India!" }
    ],
    "max_tokens": 128
  }'
```

### List available models

```bash
curl https://edge.tensormachine.ai/v1/models \
  -H "Authorization: Bearer $TENSORMACHINE_API_KEY"
```

---

## Environment variables

Never hardcode your API key. Use environment variables:

```bash
# .env (add to .gitignore)
TENSORMACHINE_API_KEY=tx_live_...
```

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["TENSORMACHINE_API_KEY"],
    base_url="https://edge.tensormachine.ai/v1",
)
```
