docs: update env-based OpenRouter profile setup
This commit is contained in:
parent
7fd845235c
commit
3b8aee4cbf
4 changed files with 62 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,3 @@
|
|||
config/profiles.yml
|
||||
*.log
|
||||
.DS_Store
|
||||
|
||||
|
|
|
|||
61
README.md
61
README.md
|
|
@ -12,7 +12,8 @@ Claude Code über einfache Profile starten:
|
|||
- `claude-free`
|
||||
- `claude-profile <name>`
|
||||
|
||||
Die eigentliche Konfiguration liegt in einer YAML-Datei.
|
||||
Die eigentliche Konfiguration der Modelle liegt in einer YAML-Datei.
|
||||
Der OpenRouter-API-Key kommt aus der Shell-Umgebung.
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
|
|
@ -42,6 +43,24 @@ chmod +x bin/claude-profile bin/install-claude-profiles lib/profiles.sh
|
|||
source ~/.bashrc
|
||||
```
|
||||
|
||||
## OpenRouter-Key setzen
|
||||
|
||||
Der OpenRouter-Key wird **nicht** in `config/profiles.yml` gespeichert.
|
||||
Stattdessen wird er über die Shell-Umgebung gesetzt.
|
||||
|
||||
Temporär für die aktuelle Session:
|
||||
|
||||
```bash
|
||||
export OPENROUTER_API_KEY="sk-or-v1-..."
|
||||
```
|
||||
|
||||
Dauerhaft in `~/.bashrc`:
|
||||
|
||||
```bash
|
||||
export OPENROUTER_API_KEY="sk-or-v1-..."
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
## Nutzung
|
||||
|
||||
```bash
|
||||
|
|
@ -57,10 +76,46 @@ Oder generisch:
|
|||
claude-profile pro
|
||||
claude-profile glm
|
||||
claude-profile kimi
|
||||
claude-profile free
|
||||
```
|
||||
|
||||
## Konfiguration
|
||||
|
||||
Die Datei `config/profiles.yml` enthält nur noch:
|
||||
|
||||
- den Startbefehl für Claude Code,
|
||||
- die OpenRouter-Base-URL,
|
||||
- die Profile,
|
||||
- die Modellnamen.
|
||||
|
||||
Beispiel:
|
||||
|
||||
```yaml
|
||||
defaults:
|
||||
claude_cmd: "claude"
|
||||
openrouter_base_url: "https://openrouter.ai/api"
|
||||
|
||||
profiles:
|
||||
pro:
|
||||
mode: "pro"
|
||||
|
||||
glm:
|
||||
mode: "openrouter"
|
||||
model: "z-ai/glm-5.2"
|
||||
|
||||
kimi:
|
||||
mode: "openrouter"
|
||||
model: "moonshotai/kimi-k2.7-code"
|
||||
|
||||
free:
|
||||
mode: "openrouter"
|
||||
model: "openrouter/free"
|
||||
```
|
||||
|
||||
## Sicherheit
|
||||
|
||||
`config/profiles.yml` enthält echte Keys und wird nicht committed.
|
||||
Nur `config/profiles.example.yml` gehört ins Repo.
|
||||
`config/profiles.yml` enthält lokale Einstellungen und bleibt unversioniert.
|
||||
Nur `config/profiles.example.yml` gehört ins Repository.
|
||||
|
||||
Keine echten API-Keys committen.
|
||||
|
||||
|
|
|
|||
|
|
@ -8,16 +8,13 @@ profiles:
|
|||
|
||||
glm:
|
||||
mode: "openrouter"
|
||||
openrouter_api_key: "REPLACE_ME"
|
||||
model: "z-ai/glm-5.2"
|
||||
|
||||
kimi:
|
||||
mode: "openrouter"
|
||||
openrouter_api_key: "REPLACE_ME"
|
||||
model: "moonshotai/kimi-k2.7-code"
|
||||
|
||||
free:
|
||||
mode: "openrouter"
|
||||
openrouter_api_key: "REPLACE_ME"
|
||||
model: "openrouter/free"
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ profile_exists() {
|
|||
}
|
||||
|
||||
clear_claude_env() {
|
||||
unset OPENROUTER_API_KEY
|
||||
unset ANTHROPIC_BASE_URL
|
||||
unset ANTHROPIC_AUTH_TOKEN
|
||||
unset ANTHROPIC_API_KEY
|
||||
|
|
@ -50,17 +49,6 @@ clear_claude_env() {
|
|||
unset CLAUDE_CODE_SUBAGENT_MODEL
|
||||
}
|
||||
|
||||
resolve_env_ref() {
|
||||
local value="$1"
|
||||
|
||||
if [[ "$value" =~ ^\$[A-Za-z_][A-Za-z0-9_]*$ ]]; then
|
||||
local var_name="${value:1}"
|
||||
printf '%s\n' "${!var_name:-}"
|
||||
else
|
||||
printf '%s\n' "$value"
|
||||
fi
|
||||
}
|
||||
|
||||
launch_profile() {
|
||||
local profile="$1"
|
||||
local mode claude_cmd base_url api_key model
|
||||
|
|
@ -89,12 +77,11 @@ launch_profile() {
|
|||
base_url="$(cfg_get '.defaults.openrouter_base_url')"
|
||||
[[ -n "$base_url" ]] || base_url="https://openrouter.ai/api"
|
||||
|
||||
api_key="$(cfg_get ".profiles.${profile}.openrouter_api_key")"
|
||||
api_key="$(resolve_env_ref "$api_key")"
|
||||
api_key="${OPENROUTER_API_KEY:-}"
|
||||
model="$(cfg_get ".profiles.${profile}.model")"
|
||||
|
||||
[[ -n "$api_key" && "$api_key" != "REPLACE_ME" ]] || {
|
||||
echo "Error: openrouter_api_key missing for profile '$profile'" >&2
|
||||
[[ -n "$api_key" ]] || {
|
||||
echo "Error: OPENROUTER_API_KEY is not set for profile '$profile'" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
@ -103,9 +90,8 @@ launch_profile() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
export OPENROUTER_API_KEY="$api_key"
|
||||
export ANTHROPIC_BASE_URL="$base_url"
|
||||
export ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY"
|
||||
export ANTHROPIC_AUTH_TOKEN="$api_key"
|
||||
export ANTHROPIC_API_KEY=""
|
||||
export ANTHROPIC_MODEL="$model"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue