# API Examples

Sample curl commands to get you started with the Tensorix API. All examples use the OpenAI-compatible endpoint.

{% hint style="info" %}
Replace `YOUR_API_KEY` with your actual Tensorix API key from [app.tensorix.ai](https://app.tensorix.ai).
{% endhint %}

***

## Basic Chat Completion

A simple chat request with GLM-5.1:

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-ai/glm-5.1",
    "messages": [
      {"role": "user", "content": "What is the capital of France?"}
    ]
  }'
```

***

## Multi-turn Conversation

Include conversation history for context:

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-ai/glm-5.1",
    "messages": [
      {"role": "user", "content": "My name is Alex"},
      {"role": "assistant", "content": "Nice to meet you, Alex! How can I help you today?"},
      {"role": "user", "content": "What is my name?"}
    ]
  }'
```

***

## Streaming Response

Get responses token-by-token for real-time output:

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-ai/glm-5.1",
    "stream": true,
    "messages": [
      {"role": "user", "content": "Write a haiku about coding"}
    ]
  }'
```

***

## Code Generation

Ask for code with a system prompt:

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-ai/glm-5.1",
    "messages": [
      {"role": "system", "content": "You are an expert Python developer. Write clean, well-documented code."},
      {"role": "user", "content": "Write a function to check if a string is a palindrome"}
    ]
  }'
```

***

## With Temperature Control

Adjust creativity with temperature (0.0 = focused, 1.0 = creative):

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "z-ai/glm-5.1",
    "temperature": 0.7,
    "messages": [
      {"role": "user", "content": "Give me 3 creative startup ideas"}
    ]
  }'
```

***

## Using MiniMax Models

Switch to MiniMax-M2.5 for different capabilities:

```bash
curl https://api.tensorix.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "minimax/minimax-m2.5",
    "messages": [
      {"role": "user", "content": "Explain quantum computing in simple terms"}
    ]
  }'
```

***

## List Available Models

Check which models are available:

```bash
curl https://api.tensorix.ai/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"
```

***

## Python Example

Using the OpenAI Python SDK:

```python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.tensorix.ai/v1"
)

response = client.chat.completions.create(
    model="z-ai/glm-5.1",
    messages=[
        {"role": "user", "content": "Hello, world!"}
    ]
)

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

***

## JavaScript/Node.js Example

Using the OpenAI Node.js SDK:

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.tensorix.ai/v1'
});

const response = await client.chat.completions.create({
  model: 'z-ai/glm-5.1',
  messages: [
    { role: 'user', content: 'Hello, world!' }
  ]
});

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

***

## Available Models

| Model            | ID                            | Best For                        |
| ---------------- | ----------------------------- | ------------------------------- |
| **GLM-5.1** ⭐    | `z-ai/glm-5.1`                | Coding, reasoning, general use  |
| **MiniMax-M2.5** | `minimax/minimax-m2.5`        | Reasoning, functions            |
| **Kimi-K2.5**    | `moonshotai/kimi-k2.5`        | Vision, functions, long context |
| **MiniMax-M2**   | `minimax/minimax-m2`          | Coding, fast responses          |
| DeepSeek V3.1    | `deepseek/deepseek-chat-v3.1` | General chat, reasoning         |
| DeepSeek R1      | `deepseek/deepseek-r1-0528`   | Complex problem solving         |

For the full list of models and pricing, visit [tensorix.ai](https://tensorix.ai).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorix.ai/api-reference/api-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
