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

# Python SDK 概要

> RAIL Score Python SDKをインストールして構成する - 同期および非同期クライアント。

## インストール

```bash theme={null}
pip install rail-score-sdk
```

プロバイダー統合のためのオプションの追加機能をインストールします：

```bash theme={null}
pip install "rail-score-sdk[openai]"       # OpenAIラッパー
pip install "rail-score-sdk[anthropic]"    # Anthropicラッパー
pip install "rail-score-sdk[google]"       # Geminiラッパー
pip install "rail-score-sdk[litellm]"      # LiteLLMラッパー
pip install "rail-score-sdk[integrations]" # すべてのLLMプロバイダー
pip install "rail-score-sdk[agents]"       # CrewAI, LangGraph, AutoGen
pip install "rail-score-sdk[telemetry]"    # OpenTelemetryサポート
pip install "rail-score-sdk[dev]"          # 開発ツール
```

## 同期クライアント

```python theme={null}
from rail_score_sdk import RailScoreClient

client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

result = client.eval(content="Your AI-generated text here", mode="basic")
print(f"RAIL Score: {result.rail_score.score}/10")
```

`RailScoreClient`は型付きデータクラスオブジェクトを返します。スコアには`result.rail_score.score`、`result.dimension_scores["fairness"].score`などでアクセスします。

## 非同期クライアント

```python theme={null}
import asyncio
from rail_score_sdk import AsyncRAILClient

async def main():
    client = AsyncRAILClient(api_key="YOUR_RAIL_API_KEY")
    result = await client.eval(content="Your text here", mode="basic")
    print(result["rail_score"]["score"])  # 生の辞書を返します

asyncio.run(main())
```

`AsyncRAILClient`はデータクラスではなく、生の辞書を返します。

## 主要クラス

| クラス               | 目的                     |
| ----------------- | ---------------------- |
| `RailScoreClient` | 同期クライアント - すべてのコアメソッド  |
| `AsyncRAILClient` | 非同期クライアント - すべてのコアメソッド |
| `RAILSession`     | 会話全体の品質を追跡             |
| `Policy`          | スコア強制のための宣言的ルール        |
| `Rule`            | 個別のポリシールール             |
| `RAILMiddleware`  | 任意の非同期LLM関数をラップ        |

## エラーハンドリング

```python theme={null}
from rail_score_sdk import (
    RailScoreClient,
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
    ContentTooHarmfulError,
)

client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

try:
    result = client.eval(content="...", mode="deep")
except AuthenticationError:
    print("APIキーを確認してください")
except InsufficientCreditsError as e:
    print(f"{e.required}クレジットが必要です。残高は{e.balance}です。")
except RateLimitError:
    print("リクエストを減速してください")
except ContentTooHarmfulError:
    print("コンテンツが安全層でブロックされました")
```

## 次は何をするか

<CardGroup cols={2}>
  <Card title="評価" icon="magnifying-glass" href="/sdk/python/evaluation">
    同期および非同期の評価例。
  </Card>

  <Card title="安全な再生成" icon="rotate" href="/sdk/python/safe-regeneration">
    基準未満のコンテンツを自動修正します。
  </Card>

  <Card title="セッションとポリシー" icon="gavel" href="/sdk/python/sessions">
    会話全体の品質を追跡します。
  </Card>

  <Card title="統合" icon="plug" href="/integrations/overview">
    OpenAI、Gemini、Anthropicのプロバイダーラッパー。
  </Card>
</CardGroup>
