> ## 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.

# グループの作成

> 新しいユーザーグループを作成する

# グループの作成

ユーザーを整理し、アクセス権限を管理するための新しいユーザー グループを作成します。

## エンドポイント

```
POST /groups
```

## 説明

このエンドポイントにより、管理者は新しいユーザー グループを作成できます。グループは、ユーザーの編成、権限の管理、システムのさまざまな部分へのアクセスの制御に使用されます。作成時にグループ名、説明、メタデータを指定できます。

## 認証

**必須**: 管理者権限を持つ API キー

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

## リクエスト本文

| パラメータ         | タイプ | 必須  | 説明                         |
| ------------- | --- | --- | -------------------------- |
| `name`        | 文字列 | はい  | グループ名                      |
| `description` | 文字列 | はい  | グループの説明                    |
| `users`       | 配列  | いいえ | グループに追加するユーザー ID の配列       |
| `status`      | 文字列 | いいえ | グループのステータス (デフォルトは「アクティブ」) |

## リクエストの例

```json theme={null}
{
  "name": "Engineering Team",
  "description": "Software engineering and development team",
  "users": ["60a7c8f5e8b4f5001f7a8c24", "60a7c8f5e8b4f5001f7a8c26"],
  "status": "Active"
}
```

## 成功の応答

**ステータス コード**: `201 Created`

```json theme={null}
{
  "success": true,
  "message": "Group created successfully",
  "group": {
    "id": "60a7c8f5e8b4f5001f7a8c25",
    "name": "Engineering Team",
    "description": "Software engineering and development team",
    "status": "Active",
    "userCount": 2,
    "users": [
      {
        "id": "60a7c8f5e8b4f5001f7a8c24",
        "name": "John Doe",
        "email": "john@example.com"
      },
      {
        "id": "60a7c8f5e8b4f5001f7a8c26",
        "name": "Jane Smith",
        "email": "jane@example.com"
      }
    ],
    "createdAt": "2024-01-20T15:30:00.000Z"
  }
}
```

### 応答フィールド

| フィールド                 | タイプ    | 説明                   |
| --------------------- | ------ | -------------------- |
| `success`             | ブール値   | 操作が成功したかどうかを示します。    |
| `message`             | 文字列    | 成功メッセージ              |
| `group`               | オブジェクト | 作成されたグループ オブジェクト     |
| `group.id`            | 文字列    | 一意のグループ識別子           |
| `group.name`          | 文字列    | グループ名                |
| `group.description`   | 文字列    | グループの説明              |
| `group.status`        | 文字列    | グループステータス            |
| `group.userCount`     | 整数     | グループ内のユーザーの数         |
| `group.users`         | 配列     | グループ内のユーザー オブジェクトの配列 |
| `group.users[].id`    | 文字列    | ユーザーID               |
| `group.users[].name`  | 文字列    | ユーザー名                |
| `group.users[].email` | 文字列    | ユーザーのメールアドレス         |
| `group.createdAt`     | 文字列    | 作成タイムスタンプ            |

## 使用例

### JavaScript

```javascript theme={null}
const createGroup = async (groupData) => {
  const response = await fetch('https://{customer.name}.hiperai.ai/api/external/groups', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(groupData)
  });
  
  return await response.json();
};

// Example usage
const groupData = {
  name: "Engineering Team",
  description: "Software engineering and development team",
  users: ["60a7c8f5e8b4f5001f7a8c24", "60a7c8f5e8b4f5001f7a8c26"],
  status: "Active"
};

const result = await createGroup(groupData);
console.log('Created group:', result.group.id);
```

### パイソン

```python theme={null}
import requests

def create_group(group_data):
    url = "https://{customer.name}.hiperai.ai/api/external/groups"
    headers = {
        "Authorization": "Bearer sk-your-api-key-here",
        "Content-Type": "application/json"
    }
    
    response = requests.post(url, headers=headers, json=group_data)
    return response.json()

# Example usage
group_data = {
    "name": "Engineering Team",
    "description": "Software engineering and development team",
    "users": ["60a7c8f5e8b4f5001f7a8c24", "60a7c8f5e8b4f5001f7a8c26"],
    "status": "Active"
}

result = create_group(group_data)
print("Created group:", result["group"]["id"])
```

### cURL

```bash theme={null}
curl -X POST "https://{customer.name}.hiperai.ai/api/external/groups" \
  -H "Authorization: Bearer sk-your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Engineering Team",
    "description": "Software engineering and development team",
    "users": ["60a7c8f5e8b4f5001f7a8c24", "60a7c8f5e8b4f5001f7a8c26"],
    "status": "Active"
  }'
```

## エラー応答

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

```json theme={null}
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Group name is required",
    "details": {
      "field": "name",
      "value": null
    }
  }
}
```

### 401 不正

```json theme={null}
{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Invalid or missing API key"
  }
}
```

### 403 禁止

```json theme={null}
{
  "success": false,
  "error": {
    "code": "INSUFFICIENT_PERMISSIONS",
    "message": "Admin privileges required"
  }
}
```

### 409 紛争

```json theme={null}
{
  "success": false,
  "error": {
    "code": "GROUP_NAME_EXISTS",
    "message": "Group name already exists"
  }
}
```

### 429 リクエストが多すぎます

```json theme={null}
{
  "success": false,
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded",
    "retryAfter": 60
  }
}
```

## 使用例

* **ユーザー組織**: グループを作成して、部門または機能ごとにユーザーを整理します。
* **アクセス制御**: 権限とアクセスを管理するためのグループを確立します。
* **チーム管理**: さまざまなチームまたはプロジェクト用のグループを作成します
* **レポート**: レポートと分析のためにユーザーを整理します
* **統合**: サードパーティ システム統合用のグループを作成します。

## レート制限

* **デフォルト**: 1 分あたり 50 リクエスト
* **毎日**: 1 日あたり 5,000 リクエスト
* **毎月**: 毎月 150,000 件のリクエスト

## 注意事項

* このエンドポイントには管理者のみがアクセスできます
* 必須フィールド: 名前と説明の両方が必須です
* ユーザー割り当て: 作成中にユーザーをグループに割り当てることができます
* ステータス: 指定しない場合、デフォルトは「アクティブ」です。
* 検証: ユーザー ID は割り当て前に検証されます。
* フラットな応答: 応答はデータ オブジェクトの下にネストされていません
* グループは作成後すぐに使用できます。


## OpenAPI

````yaml POST /groups
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:
  /groups:
    post:
      tags:
        - Group Management
      summary: Create New Group
      description: |
        Create a new group. Only accessible by administrators.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - description
              properties:
                name:
                  type: string
                  description: Group name
                  example: Engineering Team
                description:
                  type: string
                  description: Group description
                  example: Software engineering team
                users:
                  type: array
                  items:
                    type: string
                  description: Array of user IDs to add to the group
                  example:
                    - 60a7c8f5e8b4f5001f7a8c24
                    - 60a7c8f5e8b4f5001f7a8c26
                status:
                  type: string
                  enum:
                    - Active
                    - Inactive
                  default: Active
                  description: Group status
                  example: Active
            example:
              name: Engineering Team
              description: Software engineering team
              users:
                - 60a7c8f5e8b4f5001f7a8c24
                - 60a7c8f5e8b4f5001f7a8c26
              status: Active
      responses:
        '201':
          description: Group created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Group created successfully
                  group:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 60a7c8f5e8b4f5001f7a8c25
                      name:
                        type: string
                        example: Engineering Team
                      description:
                        type: string
                        example: Software engineering team
                      status:
                        type: string
                        example: Active
                      userCount:
                        type: integer
                        example: 2
                      users:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                              example: 60a7c8f5e8b4f5001f7a8c24
                            name:
                              type: string
                              example: John Doe
                            email:
                              type: string
                              example: john@example.com
                      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: Group name 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`

````