> For the complete documentation index, see [llms.txt](https://docs.digitalhumans.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalhumans.jp/dev/miniprem/api/flowise.md).

# Flowise API

{% hint style="info" %}
本ページの内容はデジタルヒューマン株式会社の正式サポート対象外です。参考情報としてご利用ください。
{% endhint %}

{% hint style="info" %}
**Chatflow API:** Flowise のチャットフローをプログラムから操作し、自動化された対話や外部システムとの連携を実現します。
{% endhint %}

## ベース URL

```
http://localhost:3000
```

## 認証

すべての API リクエストでは、Bearer トークンによる認証が必要です。

```bash
Authorization: Bearer your_api_key_here
```

{% hint style="info" %}
**API キーの確認方法:** `http://localhost:3000` の Flowise UI にアクセスし、Settings に移動して API キーをコピーしてください。
{% endhint %}

***

## Prediction API

特定のチャットフローを使用して予測（推論）を実行します。

### エンドポイント

```
POST /api/v1/prediction/{CHATFLOW_ID}
```

### リクエストヘッダー

| ヘッダー            | 値                  | 必須 |
| --------------- | ------------------ | -- |
| `Content-Type`  | `application/json` | はい |
| `Authorization` | `Bearer {API_KEY}` | はい |

### リクエストボディ

```json
{
  "question": "Your question here",
  "history": [
    {
      "type": "human",
      "message": "Previous question"
    },
    {
      "type": "ai",
      "message": "Previous answer"
    }
  ]
}
```

| フィールド               | 型      | 説明                         |
| ------------------- | ------ | -------------------------- |
| `question`          | string | ユーザーの質問または入力               |
| `history`           | array  | 任意。過去の会話履歴                 |
| `history[].type`    | string | メッセージの種類: `human` または `ai` |
| `history[].message` | string | メッセージ本文                    |

### レスポンス

```json
{
  "result": "The answer to your question...",
  "history": [
    {
      "type": "human",
      "message": "Previous question"
    },
    {
      "type": "ai",
      "message": "Previous answer"
    },
    {
      "type": "human",
      "message": "Your question here"
    },
    {
      "type": "ai",
      "message": "The answer to your question..."
    }
  ]
}
```

### 例

```bash
curl -X POST http://localhost:3000/api/v1/prediction/abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_key" \
  -d '{
    "question": "What is artificial intelligence?"
  }'
```

***

## Chatflows API

### すべてのチャットフローを一覧表示

```
GET /api/v1/chatflows
```

**レスポンス:**

```json
[
  {
    "id": "chatflow-123",
    "name": "vLLM Gemma3 Chatflow",
    "description": "Chatflow using vLLM with Buffer Memory"
  },
  {
    "id": "chatflow-456",
    "name": "Customer Support Bot",
    "description": "Support chatflow with knowledge base"
  }
]
```

### 特定のチャットフローを取得

```
GET /api/v1/chatflows/{CHATFLOW_ID}
```

**レスポンス:**

```json
{
  "id": "chatflow-123",
  "name": "vLLM Gemma3 Chatflow",
  "description": "Chatflow using vLLM with Buffer Memory",
  "nodes": [...],
  "edges": [...],
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-16T14:22:00Z"
}
```

***

## ストリーミングレスポンス

リアルタイムなストリーミングレスポンスを利用する場合は、`streaming` パラメータを追加してください。

```bash
curl -X POST http://localhost:3000/api/v1/prediction/abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_key" \
  -d '{
    "question": "Tell me a story",
    "streaming": true
  }'
```

レスポンスは Server-Sent Events (SSE) としてストリーミング配信されます。

***

## エラーレスポンス

### 401 Unauthorized

```json
{
  "error": "Unauthorized",
  "message": "Invalid or missing API key"
}
```

### 404 Not Found

```json
{
  "error": "Not Found",
  "message": "Chatflow not found"
}
```

### 500 Internal Server Error

```json
{
  "error": "Internal Server Error",
  "message": "An unexpected error occurred"
}
```

***

## 連携サンプル

### Python

```python
import requests

API_URL = "http://localhost:3000/api/v1/prediction/your-chatflow-id"
API_KEY = "your_api_key"

def query_flowise(question, history=None):
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {API_KEY}"
    }

    payload = {
        "question": question,
        "history": history or []
    }

    response = requests.post(API_URL, json=payload, headers=headers)
    return response.json()

# Usage
result = query_flowise("What is MiniPrem?")
print(result["result"])
```

### JavaScript/Node.js

```javascript
const axios = require('axios');

const API_URL = 'http://localhost:3000/api/v1/prediction/your-chatflow-id';
const API_KEY = 'your_api_key';

async function queryFlowise(question, history = []) {
  const response = await axios.post(API_URL, {
    question,
    history
  }, {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${API_KEY}`
    }
  });

  return response.data;
}

// Usage
queryFlowise('What is MiniPrem?')
  .then(result => console.log(result.result));
```

***

## 関連ドキュメント

{% hint style="info" %}
**Flowise セットアップ:** 設定とチャットフローの作成方法は [Flowise セットアップガイド](/dev/miniprem/services/flowise.md) を参照してください。\
**vLLM API:** LLM への直接アクセスについては [vLLM API リファレンス](/dev/miniprem/api/vllm.md) を参照してください。
{% endhint %}
