# MyTechAPI — Documentation

> Unified AI API gateway. One API key for chat (LLM), image, video and
> audio generation. OpenAI-compatible. Billed in credits: 1 credit =
> RM0.0000001. Base URL: https://mytechapi.my

## Quick start

1. Register at https://mytechapi.my/daftar
2. Check your chat balance in the dashboard.
3. Generate an API key at https://mytechapi.my/dashboard/kunci — shown once, keep it safe
4. Send your first request

Chat keys from Dashboard API Keys start with `sk-`. Media uses a separate legacy key and balance.

## Authentication

Send the key in the `Authorization` header:

```http
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json
```

Alternatives: `X-API-Key: <key>` or `?api_key=<key>` (use the query
form only for tools that cannot set headers).

## Endpoints

| Method | Path | Purpose |
|---|---|---|
| POST | /v1/chat/completions | Chat / LLM completion (sync or streaming) |
| POST | /v1/generations | Image, video and audio generation (async) |
| GET | /v1/generations?job_id=... | Poll a generation job |
| GET | /v1/models?modality=chat|image|video|audio|all | List models and selling prices |
| GET | /v1/credits | Chat balance and cumulative credits spent |

## Chat completions

```bash
curl https://mytechapi.my/v1/chat/completions \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mytech/opus-5.5",
    "messages": [{ "role": "user", "content": "Hello" }],
    "max_tokens": 512
  }'
```

Response follows the OpenAI format:

```json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "claude-opus-5.5-chat",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "..." },
    "finish_reason": "stop"
  }],
  "usage": { "prompt_tokens": 14, "completion_tokens": 62, "total_tokens": 76 }
}
```

**Note:** `GET /v1/models` returns chat models only by default, so coding
agents are not flooded with media models. Pass `?modality=video` (or
`image`, `audio`, `all`) to list media models.

Because it is OpenAI-compatible, the official SDK works:

```python
from openai import OpenAI
client = OpenAI(api_key="...", base_url="https://mytechapi.my/v1")
resp = client.chat.completions.create(
    model="mytech/opus-5.5",
    messages=[{"role": "user", "content": "Hello"}],
)
```

## Media generation

Asynchronous — three steps. See the full tutorial at
https://mytechapi.my/docs/media.md

**Step 1 — submit**

```bash
curl https://mytechapi.my/v1/generations \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mytech/veo-3.1-text-to-video-quality-1080p",
    "prompt": "a cat leaping across a rooftop",
    "duration": 6
  }'
```

```json
{
  "job_id": "1f3c8a2e-...",
  "status": "running",
  "charged_credits": 84787500,
  "poll": "/v1/generations?job_id=1f3c8a2e-..."
}
```

**Step 2 — poll** (every 3–5 seconds)

```bash
curl "https://mytechapi.my/v1/generations?job_id=1f3c8a2e-..." \
  -H "Authorization: Bearer ***"
```

Statuses: `running` · `succeeded` · `failed`.

**Step 3 — download**

```json
{
  "status": "succeeded",
  "output_urls": ["/api/studio/media/1f3c8a2e-..."]
}
```

- `/api/studio/media/...` — prefix with https://mytechapi.my and send the same Authorization header.
- `https://...` — fetch directly, no header needed.

Credits are held on submit and refunded in full if the job fails.

## Parameters

| Model family | Valid duration (seconds) |
|---|---|
| Veo 3.1 | 4, 6, 8 |
| Grok Imagine | 6, 10 |
| Runway | 5 (fixed) |
| Kling 4.0 | 3–30 |
| MiniMax H3 | 6, 10 |
| Seedance 2.5 | 4–30 |
| Wan 3.0 | 2–30 |
| Gemini Omni Flash 1.2 | 3–15 |

Out-of-range duration values are rounded to the nearest valid value and
billed at the actual generated duration.

Input fields:

- `image_urls` — array of publicly reachable image URLs (image-to-video, image-to-image)
- `first_frame_url`, `keyframe_urls`, `last_frame_url` — keyframe-to-video
- `audio_url` — required for talking-avatar models (MP3/WAV, 4–300s, max 15MB)

## Building a website or app

Never call this API from browser JavaScript — the key would be visible
in DevTools. Call it from your server and proxy from the frontend:

```
Browser  →  your backend (.env: MYTECH_API_KEY)  →  MyTechAPI
```

The API does not send CORS headers, which is deliberate: it protects
keys. Never use `NEXT_PUBLIC_*` or `VITE_*` for the key — those are
shipped to the browser.

## MCP server and CLI

Local stdio MCP server and CLI, zero npm dependencies, Node 18+.
Download: https://mytechapi.my/myt-mcp.mjs

```bash
export MYTECH_API_KEY="YOUR_MYTECH_API_KEY"
node myt-mcp.mjs list --modality video
node myt-mcp.mjs doc mytech/veo-3.1-text-to-video-quality-1080p
node myt-mcp.mjs run mytech/veo-3.1-text-to-video-quality-1080p \
  --input '{"prompt":"a cat on a rooftop","duration":6}' --max-credits 100000000
node myt-mcp.mjs status <job_id> --wait 60
node myt-mcp.mjs mcp    # MCP server on stdio
```

MCP tools exposed: `mytech_list_models`, `mytech_model_spec`,
`mytech_credit_balance`, `mytech_submit_task`, `mytech_task_status`,
`mytech_chat`.

Register in Claude Desktop or Cursor (`mcp.json` /
`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "mytechapi": {
      "command": "node",
      "args": ["/absolute/path/to/myt-mcp.mjs", "mcp"],
      "env": { "MYTECH_API_KEY": "YOUR_MYTECH_API_KEY" }
    }
  }
}
```

Environment variables: `MYTECH_API_KEY`, `MYTECH_BASE_URL`,
`MYTECH_MAX_CREDITS` (per-task credit ceiling, 0 = disabled),
`MYTECH_OUTPUT_DIR`.

`--max-credits` performs a pre-flight catalogue price check and refuses
to send the task if the estimate exceeds the ceiling, preventing
unexpected spend. Exit code `3` means blocked before sending.

## Models and pricing

Live catalogue: https://mytechapi.my/models

Each model's price is per unit according to its billing mode
(`per_1m_tokens`, `per_image`, `per_video`, `per_second`, `per_1k_chars`,
`per_request`). Query `GET /v1/models` for the authoritative list.

## Errors

| Code | Type | Meaning |
|---|---|---|
| 401 | missing_api_key | No key in the Authorization header |
| 401 | invalid_api_key | Key invalid or revoked |
| 402 | insufficient_credit | Balance too low for the request |
| 404 | model_not_found | Model does not exist or is inactive |
| 429 | rate_limit_exceeded | Key rate limit exceeded |

A failed media job returns `status: "failed"` with `charged_credits: 0`
(held credits refunded in full).

## Credits

RM1 equals 10 million chat credits. The balance endpoint returns `balance`, `rm_equivalent` and `used_credits`. Older chat keys without wallet permission can return HTTP 403. Generate a new chat key for balance access. See Usage Log for individual requests.
