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

# 新しいユーザーの作成

> Create a new user account. Only accessible by administrators.


# 新しいユーザーを作成する

新しいユーザー アカウントを作成します。管理者のみがアクセスできます。

## エンドポイント

```
POST /users
```

## 説明

このエンドポイントにより、管理者はシステム内に新しいユーザー アカウントを作成できます。ロール、ライセンス、認証タイプなどのさまざまなユーザー属性を指定できます。これは、適切な権限を必要とする管理エンドポイントです。

## ユーザー作成フロー

**基本認証** (`authType: "basic"`): ユーザーは、パスワード設定リンクが記載されたウェルカム電子メールを受信します。アカウントは、パスワードが設定されるまで検証されずに作成されます。

**エンタープライズ SSO** (`authType: "enterprise"`): ユーザーは検証済みで作成され、エンタープライズ SSO (Auth0、Microsoft AD など) 経由でサインインできます。パスワードの設定は必要ありません。

## 認証

必須。 API キーを Authorization ヘッダーに含めます。

```bash theme={null}
Authorization: Bearer sk-your-api-key-here
```

## リクエスト

### リクエスト本文

| パラメータ            | タイプ  | 必須  | デフォルト | 説明                                                |
| ---------------- | ---- | --- | ----- | ------------------------------------------------- |
| `name`           | 文字列  | はい  | -     | ユーザーのフルネーム                                        |
| `username`       | 文字列  | いいえ | -     | 一意のユーザー名 (指定しない場合は電子メールから自動生成されます)                |
| `email`          | 文字列  | はい  | -     | ユーザーのメールアドレス                                      |
| `role`           | 文字列  | いいえ | ユーザー  | ユーザーのロール (管理者、ユーザー、globalReader)                  |
| `license`        | 文字列  | いいえ | 必須    | ユーザーのライセンス層 (Essential、Growth、Ultra、Early Access) |
| `roleId`         | 文字列  | いいえ | -     | カスタム ロール ID (MongoDB ObjectId)                    |
| `setupCompleted` | ブール値 | いいえ | 偽     | ユーザーセットアップが完了しているかどうか                             |
| `authType`       | 文字列  | いいえ | 基本    | 認証タイプ (ベーシック、エンタープライズ)                            |

### リクエストの例

```bash theme={null}
curl -X POST "https://{customer.name}.hiperai.ai/api/external/users" \
  -H "Authorization: Bearer sk-your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "username": "johndoe",
    "email": "john@example.com",
    "role": "user",
    "license": "Growth",
    "setupCompleted": false,
    "authType": "enterprise"
  }'
```

## 応答

### 成功の応答 (201)

```json theme={null}
{
  "success": true,
  "message": "User created successfully",
  "user": {
    "id": "60a7c8f5e8b4f5001f7a8c23",
    "name": "John Doe",
    "username": "johndoe",
    "email": "john@example.com",
    "role": "user",
    "license": "Growth",
    "status": 1,
    "isVerified": false,
    "setupCompleted": false,
    "authType": "basic",
    "createdAt": "2024-01-15T10:30:00.000Z"
  }
}
```

### 応答フィールド

| フィールド                 | タイプ    | 説明                     |
| --------------------- | ------ | ---------------------- |
| `success`             | ブール値   | リクエストが成功した場合は常に `true` |
| `message`             | 文字列    | 成功メッセージ                |
| `user`                | オブジェクト | 作成されたユーザー オブジェクト       |
| `user.id`             | 文字列    | ユーザーの一意の識別子            |
| `user.name`           | 文字列    | ユーザーのフルネーム             |
| `user.username`       | 文字列    | ユーザーのユーザー名             |
| `user.email`          | 文字列    | ユーザーのメールアドレス           |
| `user.role`           | 文字列    | ユーザーの役割                |
| `user.license`        | 文字列    | ユーザーのライセンス層            |
| `user.status`         | 整数     | ユーザーステータス (1=アクティブ)    |
| `user.isVerified`     | ブール値   | ユーザーが認証されているかどうか       |
| `user.setupCompleted` | ブール値   | ユーザーセットアップが完了しているかどうか  |
| `user.authType`       | 文字列    | 認証タイプ                  |
| `user.createdAt`      | 文字列    | ユーザー作成のタイムスタンプ         |

## 使用例

### JavaScript

```javascript theme={null}
const response = await fetch('https://{customer.name}.hiperai.ai/api/external/users', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-your-api-key-here',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'John Doe',
    username: 'johndoe',
    email: 'john@example.com',
    role: 'user',
    license: 'Growth'
  })
});

const data = await response.json();

if (data.success) {
  console.log('User created:', data.user.name);
  console.log('User ID:', data.user.id);
}
```

### パイソン

```python theme={null}
import requests

headers = {
    'Authorization': 'Bearer sk-your-api-key-here',
    'Content-Type': 'application/json'
}

data = {
    'name': 'John Doe',
    'username': 'johndoe',
    'email': 'john@example.com',
    'role': 'user',
    'license': 'Growth'
}

response = requests.post('https://{customer.name}.hiperai.ai/api/external/users', 
                       headers=headers, json=data)
result = response.json()

if result['success']:
    print('User created:', result['user']['name'])
    print('User ID:', result['user']['id'])
```

### cURL

```bash theme={null}
curl -X POST "https://{customer.name}.hiperai.ai/api/external/users" \
  -H "Authorization: Bearer sk-your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "username": "johndoe",
    "email": "john@example.com",
    "role": "user",
    "license": "Growth"
  }'
```

## エラー応答

### 400 不正なリクエスト

```json theme={null}
{
  "success": false,
  "error": "Invalid request parameters",
  "message": "The 'name' field is required"
}
```

### 400 無効な認証タイプ

```json theme={null}
{
  "success": false,
  "error": "Invalid authType",
  "message": "authType must be either \"basic\" or \"enterprise\""
}
```

### 400 必須フィールドがありません

```json theme={null}
{
  "success": false,
  "error": "Missing required fields",
  "message": "Name and email are required"
}
```

### 401 不正

```json theme={null}
{
  "success": false,
  "error": "Invalid API key",
  "message": "The provided API key is invalid or has been revoked"
}
```

### 403 禁止

```json theme={null}
{
  "success": false,
  "error": "Access denied",
  "message": "Admin access required"
}
```

### 409 紛争

```json theme={null}
{
  "success": false,
  "error": "User already exists",
  "message": "A user with this email already exists"
}
```

## 検証とビジネス ルール

* **ライセンス値**: 許可されたライセンス (`Essential`、`Growth`、`Ultra`、`Early Access`) のいずれかである必要があります。無効な値は 400 を返します。
* **ライセンス容量**: `checkLicenseCapacity` 経由で強制されます。選択した層の容量がいっぱいの場合は、400 を返します。
* **電子メールの正規化**: 検証および保存前に小文字化およびトリミングされます。
* **ユーザー名の正規化**: 検証および保存前に小文字化およびトリミングされます。指定されていない場合は、電子メールから自動生成されます。
* **電子メール形式**: 単純な正規表現で検証されます。無効なメールは 400 を返します。
* **ユーザー名の形式**: `^[a-z0-9.-]{3,30}$` と一致する必要があります。無効なユーザー名は 400 を返します。
* **一意性**: `email`、`username`、および `name` は一意である必要があります。競合は 409 を返します。
* **電子メールによる招待動作**: 基本認証の場合、ユーザーはパスワード設定リンクが記載されたウェルカム電子メールを受信します。

## 正規化と保存

* `email` および `username` は常に小文字で保存され、トリミングされます。

## 典型的なエラーの形状

### 400 無効なライセンス

```json theme={null}
{
  "success": false,
  "error": "Invalid license",
  "message": "License must be one of: Essential, Growth, Ultra, Early Access"
}
```

### 400 ライセンスは使用できません

```json theme={null}
{
  "success": false,
  "error": "License unavailable",
  "message": "No Growth licenses available (used/limit)"
}
```

### 400 無効な電子メール

```json theme={null}
{
  "success": false,
  "error": "Invalid email",
  "message": "Email format is invalid"
}
```

### 400 無効なユーザー名

```json theme={null}
{
  "success": false,
  "error": "Invalid username",
  "message": "Username must be 3-30 chars, lowercase letters, digits, \".\", "-", or \"\""
}
```

### 409 対立（独自性）

```json theme={null}
{
  "success": false,
  "error": "Email/Username/Name already exists",
  "message": "A user with this email already exists"
}
```

## ユーザーの役割

| 役割             | 説明        | 権限                 |
| -------------- | --------- | ------------------ |
| `admin`        | 管理者       | フルシステムアクセス         |
| `user`         | 一般ユーザー    | 標準ユーザー アクセス        |
| `globalReader` | グローバルリーダー | 読み取り専用の管理パネルへのアクセス |

## ライセンス階層

| ライセンス          | 説明         | 特長         |
| -------------- | ---------- | ---------- |
| `Essential`    | 基本レベル      | 機能が制限されている |
| `Growth`       | プロフェッショナル層 | 強化された機能    |
| `Ultra`        | プレミアム層     | フル機能       |
| `Early Access` | 早期アクセス層    | ベータ版の機能    |

## 認証タイプ

| タイプ          | 説明                                      |
| ------------ | --------------------------------------- |
| `basic`      | ユーザー名/パスワード認証 (ユーザーはパスワード設定メールを受け取ります)  |
| `enterprise` | エンタープライズ SSO 統合 (Auth0、Microsoft AD など) |

## 使用例

* **ユーザー オンボーディング**: チーム メンバー用の新しいユーザー アカウントを作成します
* **パスワードレス オンボーディング**: 独自のパスワードを設定するための電子メール招待を受信するユーザーを作成します
* **SSO 統合**: 外部 ID プロバイダー経由で認証するユーザーを作成します。
* **ユーザーの一括作成**: プログラムで複数のユーザーを作成します
* **統合**: 外部システムからユーザーを作成
* **管理タスク**: API を介してユーザー アカウントを管理する

## レート制限

このエンドポイントは、標準のレート制限に従います。

* 1 分あたり 60 リクエスト
* 1 時間あたり 1000 リクエスト


## OpenAPI

````yaml POST /users
openapi: 3.0.3
info:
  title: SecureAI External API
  description: >
    SecureAI External API provides AI chat completion and image generation
    capabilities with knowledge base retrieval, 

    security policies, and comprehensive usage tracking. This API is designed
    for external developers 

    and integrations using API key authentication.


    ## Key Features

    - **RAG (Retrieval-Augmented Generation)**: Automatically search knowledge
    bases for relevant context

    - **Multi-Model Support**: OpenAI, Anthropic, Google, Meta, and other AI
    models

    - **Model Redundancy & Failover**: Caller-defined failover chains (primary +
    fallbacks) with per-attempt timeouts

    - **OpenAI-Compatible Endpoint**: Point any OpenAI SDK at `/api/external/v1`
    — no code changes

    - **Image Generation**: Generate and edit images using Google Gemini 2.5
    Flash Image

    - **Speech-to-Speech (S2S)**: Real-time voice conversations using OpenAI
    Realtime API with WebRTC

    - **Security Policies**: SMLTP policy enforcement, per-call Prompt Shield,
    and signed compliance receipts

    - **Usage Tracking**: Comprehensive usage monitoring, self-service quota,
    and rate limiting

    - **Knowledge Base Integration**: Access to personal and shared knowledge
    bases

    - **User Management**: Complete user, group, and role management
    capabilities

    - **Audit Logging**: Comprehensive activity and security audit logs


    ## Authentication

    All endpoints (except health check) require API key authentication using
    Bearer token:

    ```

    Authorization: Bearer sk-your-api-key-here

    ```


    ## Billing and Usage

    By default, API requests are billed to the user account that owns the API
    key. You can specify 

    a different user to bill by including the `user_id` parameter in your
    request. This allows for:

    - Multi-tenant applications with per-user billing

    - Flexible completion limit management

    - Per-user "Usage by Model" settings


    ## Rate Limits

    - Default: 60 requests per minute, 1000 requests per hour

    - Daily limits: 100 requests (configurable)

    - Monthly limits: 10,000 requests (configurable)


    ## Base URL

    ```

    https://secureai.hiperai.ai/api/external

    ```
  version: 1.1.0
  contact:
    name: SecureAI Support
    email: support@secureai.hiperai.ai
  license:
    name: Proprietary
    url: https://secureai.hiperai.ai/terms
servers:
  - url: https://secureai.hiperai.ai/api/external
    description: Production server
  - url: http://localhost:3010/api/external
    description: Development server
security:
  - ApiKeyAuth: []
tags:
  - name: System
    description: System health and status endpoints
  - name: Discovery
    description: Endpoints to discover available models, indexes, and policies
  - name: Chat
    description: AI chat completion endpoints
  - name: User Management
    description: Endpoints for managing user accounts and roles
  - name: Index Management
    description: Endpoints for managing knowledge base indexes
  - name: Group Management
    description: Endpoints for managing user groups
  - name: SMLTP Security
    description: Endpoints for managing SMLTP security policies and audit logs
  - name: Role Management
    description: Endpoints for managing user roles
  - name: Activity Logs
    description: Endpoints for retrieving activity logs
externalDocs:
  description: SecureAI Documentation
  url: https://secureai.hiperai.ai/docs
paths:
  /users:
    post:
      tags:
        - User Management
      summary: Create New User
      description: |
        Create a new user account. Only accessible by administrators.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - username
                - email
                - password
              properties:
                name:
                  type: string
                  description: User's full name
                  example: John Doe
                username:
                  type: string
                  description: Unique username
                  example: johndoe
                email:
                  type: string
                  format: email
                  description: User's email address
                  example: john@example.com
                password:
                  type: string
                  description: User's password
                  example: securepassword123
                role:
                  type: string
                  enum:
                    - admin
                    - user
                    - globalReader
                  default: user
                  description: User's role
                  example: user
                license:
                  type: string
                  enum:
                    - Essential
                    - Growth
                    - Ultra
                    - Early Access
                  default: Essential
                  description: User's license tier
                  example: Growth
                roleId:
                  type: string
                  description: Custom role ID (MongoDB ObjectId)
                  example: 60a7c8f5e8b4f5001f7a8c24
                setupCompleted:
                  type: boolean
                  default: false
                  description: Whether user setup is completed
                  example: false
                authType:
                  type: string
                  enum:
                    - basic
                    - auth0
                  default: basic
                  description: Authentication type
                  example: basic
            example:
              name: John Doe
              username: johndoe
              email: john@example.com
              password: securepassword123
              role: user
              license: Growth
              setupCompleted: false
              authType: basic
      responses:
        '201':
          description: User created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: User created successfully
                  user:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 60a7c8f5e8b4f5001f7a8c23
                      name:
                        type: string
                        example: John Doe
                      username:
                        type: string
                        example: johndoe
                      email:
                        type: string
                        example: john@example.com
                      role:
                        type: string
                        example: user
                      license:
                        type: string
                        example: Growth
                      status:
                        type: integer
                        example: 1
                      isVerified:
                        type: boolean
                        example: true
                      setupCompleted:
                        type: boolean
                        example: false
                      authType:
                        type: string
                        example: basic
                      createdAt:
                        type: string
                        format: date-time
                        example: '2024-01-15T10:30:00.000Z'
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Access denied - admin only
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: User already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
          example: Invalid API key
        message:
          type: string
          example: The provided API key is invalid or has been revoked
        request_id:
          type: string
          example: req-abc123
          description: Request ID for tracking (if available)
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      description: |
        API key authentication using Bearer token format.
        Example: `Authorization: Bearer sk-your-api-key-here`

````