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

# DeepSeek (AI)

> API key dan model untuk generate dokumen trainer.

AI Mentor memakai **DeepSeek** sebagai provider AI utama untuk generate dokumen, enricher, dan workspace chat.

<Frame>
  <img src="https://cdn.deepseek.com/logo.png" alt="Logo DeepSeek" width="160" />
</Frame>

**Console:** [platform.deepseek.com](https://platform.deepseek.com)\
**Docs:** [api-docs.deepseek.com](https://api-docs.deepseek.com/)

## Env di project

```bash theme={null}
DEEPSEEK_API_KEY=sk-...
DEEPSEEK_BASE_URL=https://api.deepseek.com/v1
AI_PROVIDER=deepseek
AI_MODEL=deepseek-v4-flash
```

`DEEPSEEK_API_KEY` termasuk **secret wajib** sebelum `./thub secrets push`.

## Setup API key

<Steps>
  <Step title="Daftar developer">
    Buka [platform.deepseek.com](https://platform.deepseek.com) (bukan chat.deepseek.com). Verifikasi email.
  </Step>

  <Step title="Top-up saldo">
    Sidebar → **Billing** → tambah payment method + top-up. API tidak jalan tanpa balance.
  </Step>

  <Step title="Buat API key">
    Sidebar → **API Keys** → **Create new API key**\
    Salin `sk-...` — **hanya sekali**.
  </Step>

  <Step title="Tes curl">
    ```bash theme={null}
    curl https://api.deepseek.com/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
      -d '{
        "model": "deepseek-v4-flash",
        "messages": [{"role": "user", "content": "Halo"}],
        "stream": false
      }'
    ```
  </Step>

  <Step title="Simpan di .env">
    ```bash theme={null}
    # .env shared
    DEEPSEEK_API_KEY=sk-...
    ./thub env merge
    ./thub secrets push
    ```
  </Step>
</Steps>

## Model yang dipakai

| Model               | Kegunaan                                 |
| ------------------- | ---------------------------------------- |
| `deepseek-v4-flash` | Default — cepat, murah, generate dokumen |
| `deepseek-v4-pro`   | Kualitas lebih tinggi (opsional)         |

Base URL kompatibel OpenAI SDK — project memanggil `/chat/completions` dengan `response_format: json_object` untuk output terstruktur.

## Monitoring usage

Dashboard → **Usage** — pantau token & biaya sebelum production traffic naik.

## Troubleshooting

| Masalah                      | Solusi                                                |
| ---------------------------- | ----------------------------------------------------- |
| 401 Unauthorized             | Key salah atau revoked                                |
| 402 / billing                | Top-up balance di platform                            |
| JSON parse error di generate | Retry otomatis di worker; cek model & prompt          |
| Rate limit 429               | Kurangi concurrency generate; backoff sudah di worker |

Docs: [First API call](https://api-docs.deepseek.com/) · [Authentication](https://api-docs.deepseek.com/api/deepseek-api)
