Output SDK ワークフロー内で暗号化されたシークレット(認証情報)を @outputai/credentials を使って保存・参照できます。 次のような場合に使用: API キーやデータベースのパスワード、サードパーティ製サービスのトークンを組み込むとき
Store and reference encrypted secrets in Output SDK workflows using @outputai/credentials. Use when integrating API keys, database passwords, or third-party tokens.
@outputai/credentials パッケージは、Output SDK のワークフローに対して、暗号化された認証情報(APIキーやトークンなど)を安全に管理する機能を提供します。従来の process.env パターンに代わる、構造化された暗号化YAML形式のシステムで、スコープ付き認証情報と深い階層マージに対応しています。
process.env から暗号化認証情報への移行MissingCredentialError、MissingKeyError)のデバッグimport { credentials } from '@outputai/credentials';
credentials.get(path, defaultValue?)オプションのデフォルト値付きで安全に読み取ります。例外をスローしません。
// 値またはundefinedを返す
const region = credentials.get('aws.region');
// 値またはデフォルトを返す
const region = credentials.get('aws.region', 'us-east-1');
credentials.require(path)必須の読み取り。見つからない場合は MissingCredentialError をスローします。
const apiKey = credentials.require('anthropic.api_key');
import { MissingCredentialError, MissingKeyError } from '@outputai/credentials';
| エラー | 発生時 | 対処方法 |
|---|---|---|
MissingCredentialError |
credentials.require() の指定パスが見つからない |
output credentials edit で認証情報を追加 |
MissingKeyError |
復号化キーがない | OUTPUT_CREDENTIALS_KEY 環境変数を設定するか、.key ファイルを作成 |
# 認証情報を初期化(キーを生成し、暗号化YAMLテンプレートを作成)
output credentials init # グローバル
output credentials init -e production # 環境別
output credentials init -w payment_processing # ワークフロー別
# 認証情報を編集(復号化、$EDITOR で開く、保存時に再暗号化)
output credentials edit # グローバル
output credentials edit -e production # 環境別
output credentials edit -w payment_processing # ワークフロー別
# 復号化された認証情報を表示(デバッグ用)
output credentials show # グローバル
output credentials show -e development # 環境別
# 単一の認証情報値を取得
output credentials get anthropic.api_key # グローバル
output credentials get stripe.key -w payment_processing # ワークフロー別
フラグ:
-e / --environment: 対象環境(production、development など)-w / --workflow: 特定のワークフローを対象-f / --force: 既存の認証情報を上書き(init のみ)-e と -w は同時に指定できませんconfig/credentials.yml.enc # 暗号化YAML
config/credentials.key # 復号化キー(コミットしないこと)
キー環境変数:OUTPUT_CREDENTIALS_KEY
config/credentials/production.yml.enc
config/credentials/production.key
キー環境変数:OUTPUT_CREDENTIALS_KEY_PRODUCTION
src/workflows/{name}/credentials.yml.enc
src/workflows/{name}/credentials.key
キー環境変数:OUTPUT_CREDENTIALS_KEY_{WORKFLOW_NAME}(大文字)
各スコープについて、キーは以下の順序で探索されます:
OUTPUT_CREDENTIALS_KEY、OUTPUT_CREDENTIALS_KEY_{ENV}、または OUTPUT_CREDENTIALS_KEY_{WORKFLOW})config/credentials.key)MissingKeyError をスローワークフロー別キーが存在しない場合、ワークフロー認証情報はグローバルキーにフォールバックします。
ワークフローが独自の認証情報を持つ場合、グローバル認証情報に対して深い階層でマージされます。同じパスではワークフロー側の値が優先されます:
# グローバル (config/credentials.yml.enc)
anthropic:
api_key: sk-ant-global
aws:
region: us-east-1
# ワークフロー (src/workflows/my_workflow/credentials.yml.enc)
anthropic:
api_key: sk-ant-workflow-specific
stripe:
secret_key: sk_live_workflow
# 実行時のマージ結果:
# anthropic.api_key -> sk-ant-workflow-specific (ワークフロー側で上書き)
# aws.region -> us-east-1 (グローバルから)
# stripe.secret_key -> sk_live_workflow (ワークフロー側で追加)
process.env からの移行import { createKyClient } from '@outputai/http';
const API_KEY = process.env.SERVICE_API_KEY || '';
const client = createKyClient({
prefix: 'https://api.service.com',
headers: { Authorization: `Bearer ${API_KEY}` }
});
import { createKyClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
const apiKey = credentials.require('service.api_key');
const client = createKyClient({
prefix: 'https://api.service.com',
headers: { Authorization: `Bearer ${apiKey}` }
});
output credentials init を実行して暗号化ファイルとキーを生成output credentials edit を実行して認証情報を追加process.env.X の参照を credentials.require('x') または credentials.get('x', default) に置き換え.env ファイルから環境変数を削除.gitignore に *.key を追加デフォルトの暗号化YAML形式をVaultやAWS Secrets Managerなど別のシステムに置き換えられます:
import { setProvider } from '@outputai/credentials';
setProvider({
loadGlobal: ({ environment }) => {
return fetchFromVault(`credentials/${environment || 'default'}`);
},
loadForWorkflow: ({ workflowName, environment }) => {
return fetchFromVault(`workflows/${workflowName}`) ?? null;
}
});
interface CredentialsProvider {
loadGlobal(context: { environment: string | undefined }): Record<string, unknown>;
loadForWorkflow(context: {
workflowName: string;
workflowDir: string | undefined;
environment?: string | undefined;
}): Record<string, unknown> | null;
}
.key ファイルは絶対にコミットしない — .gitignore に *.key を追加.yml.enc ファイルはコミット可能 — キーなしでは読み取り不可0o600(所有者のみ読み書き可)で作成edit 中にプレーンテキストはヌルバイトで上書きしてから削除OUTPUT_CREDENTIALS_KEY を設定@outputai/credentials から credentials をインポートcredentials.require() を使用(process.env ではなく)credentials.get() をデフォルト値付きで使用*.key を .gitignore に記載output credentials init で認証情報を初期化output credentials edit で認証情報を追加output-credentials-init — 認証情報ファイルの初期化output-credentials-edit — 認証情報の表示と編集output-credentials-env-vars — credential: 規約を使った認証情報の環境変数化output-dev-http-client-create — 認証情報を使う HTTP クライアントの作成output-dev-step-function — ステップ関数での認証情報の使用output-error-http-client — HTTP クライアントの問題対応The @outputai/credentials package provides encrypted secrets management for Output SDK workflows. It replaces process.env patterns with a structured, encrypted YAML-based system that supports scoped credentials with deep merging.
process.env to encrypted credentialsMissingCredentialError, MissingKeyError)import { credentials } from '@outputai/credentials';
credentials.get(path, defaultValue?)Safe read with optional default. Never throws.
// Returns value or undefined
const region = credentials.get('aws.region');
// Returns value or default
const region = credentials.get('aws.region', 'us-east-1');
credentials.require(path)Strict read. Throws MissingCredentialError if not found.
const apiKey = credentials.require('anthropic.api_key');
import { MissingCredentialError, MissingKeyError } from '@outputai/credentials';
| Error | Thrown When | Fix |
|---|---|---|
MissingCredentialError |
credentials.require() path not found |
Add the credential via output credentials edit |
MissingKeyError |
No decryption key available | Set OUTPUT_CREDENTIALS_KEY env var or create .key file |
# Initialize credentials (generates key + encrypted YAML template)
output credentials init # Global
output credentials init -e production # Environment-specific
output credentials init -w payment_processing # Workflow-specific
# Edit credentials (decrypts, opens $EDITOR, re-encrypts on save)
output credentials edit # Global
output credentials edit -e production # Environment
output credentials edit -w payment_processing # Workflow
# Show decrypted credentials (debugging)
output credentials show # Global
output credentials show -e development # Environment
# Get single credential value
output credentials get anthropic.api_key # Global
output credentials get stripe.key -w payment_processing # Workflow
Flags:
-e / --environment: Target environment (production, development)-w / --workflow: Target a specific workflow-f / --force: Overwrite existing credentials (init only)-e and -w are mutually exclusiveconfig/credentials.yml.enc # Encrypted YAML
config/credentials.key # Decryption key (DO NOT COMMIT)
Key env var: OUTPUT_CREDENTIALS_KEY
config/credentials/production.yml.enc
config/credentials/production.key
Key env var: OUTPUT_CREDENTIALS_KEY_PRODUCTION
src/workflows/{name}/credentials.yml.enc
src/workflows/{name}/credentials.key
Key env var: OUTPUT_CREDENTIALS_KEY_{WORKFLOW_NAME} (uppercased)
For each scope, the key is resolved in order:
OUTPUT_CREDENTIALS_KEY, OUTPUT_CREDENTIALS_KEY_{ENV}, or OUTPUT_CREDENTIALS_KEY_{WORKFLOW})config/credentials.key)MissingKeyError if neither foundWorkflow credentials fall back to the global key if no workflow-specific key exists.
When a workflow has its own credentials, they deep-merge over global credentials. Workflow values win at the same path:
# Global (config/credentials.yml.enc)
anthropic:
api_key: sk-ant-global
aws:
region: us-east-1
# Workflow (src/workflows/my_workflow/credentials.yml.enc)
anthropic:
api_key: sk-ant-workflow-specific
stripe:
secret_key: sk_live_workflow
# Merged result at runtime:
# anthropic.api_key -> sk-ant-workflow-specific (overridden by workflow)
# aws.region -> us-east-1 (from global)
# stripe.secret_key -> sk_live_workflow (added by workflow)
process.envimport { createKyClient } from '@outputai/http';
const API_KEY = process.env.SERVICE_API_KEY || '';
const client = createKyClient({
prefix: 'https://api.service.com',
headers: { Authorization: `Bearer ${API_KEY}` }
});
import { createKyClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
const apiKey = credentials.require('service.api_key');
const client = createKyClient({
prefix: 'https://api.service.com',
headers: { Authorization: `Bearer ${apiKey}` }
});
output credentials init to create the encrypted file and keyoutput credentials edit to add your secretsprocess.env.X reads with credentials.require('x') or credentials.get('x', default).env files*.key to .gitignoreReplace the default encrypted YAML backend with Vault, AWS Secrets Manager, etc.:
import { setProvider } from '@outputai/credentials';
setProvider({
loadGlobal: ({ environment }) => {
return fetchFromVault(`credentials/${environment || 'default'}`);
},
loadForWorkflow: ({ workflowName, environment }) => {
return fetchFromVault(`workflows/${workflowName}`) ?? null;
}
});
interface CredentialsProvider {
loadGlobal(context: { environment: string | undefined }): Record<string, unknown>;
loadForWorkflow(context: {
workflowName: string;
workflowDir: string | undefined;
environment?: string | undefined;
}): Record<string, unknown> | null;
}
.key files - Add *.key to .gitignore.yml.enc files - Cannot be read without the key0o600 (owner-only read/write)editOUTPUT_CREDENTIALS_KEY in your pipelinecredentials imported from @outputai/credentialscredentials.require() used for mandatory secrets (not process.env)credentials.get() used with default for optional values*.key listed in .gitignoreoutput credentials initoutput credentials editoutput-credentials-init - Initializing credentials files for the first timeoutput-credentials-edit - Viewing and editing credential valuesoutput-credentials-env-vars - Wiring credentials to env vars with the credential: conventionoutput-dev-http-client-create - Creating HTTP clients that use credentialsoutput-dev-step-function - Using credentials in step functionsoutput-error-http-client - Troubleshooting HTTP client issues原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。