0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Aider を OpenAI 互換エンドポイントで使う:`/v1` と `openai/` プレフィックスの落とし穴

0
Posted at

Aider(独立した CLI ペアプログラミングツール)は LiteLLM 経由で OpenAI 互換 API に接続できます。セットアップでつまずく原因はほぼ 2 つで、ベース URL は /v1 で終わらせること、モデル名に openai/ プレフィックスを付けることです。

環境変数で接続する

export OPENAI_API_BASE='https://api.china-aiapi.com/v1'
export OPENAI_API_KEY="$LLM_API_KEY"

# まず安いリクエストを 1 回だけ投げて配線を確認
curl -sS "$OPENAI_API_BASE/chat/completions" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"MODEL_ID","messages":[{"role":"user","content":"ok"}],"max_tokens":5}'

cd /path/to/repo
aider --model openai/MODEL_ID

MODEL_ID は使うエンドポイントが返すモデル ID に置き換えてください。

シークレットをコミットせずに設定を残す

リポジトリ直下の .aider.conf.yml:

openai-api-base: https://api.china-aiapi.com/v1
model: openai/MODEL_ID
# キーは OPENAI_API_KEY / AIDER_OPENAI_API_KEY に置く

よくある落とし穴

  1. …/v1/v1 になる:Aider 側が /chat/completions を付け足すので、ベース URL は /v1 で止める。
  2. openai/ なしの MODEL_ID:LiteLLM が組み込みプロバイダを探しに行き、エラーがモデルの問題に見える。
  3. API キーをコミット対象の YAML に書いてしまう。

同等のフラグ:--openai-api-base、--openai-api-key、環境変数 AIDER_OPENAI_API_BASE。


開示:筆者は APIGOTO チームで働いています。OpenAI・Anthropic・Google とは無関係です。 Aider は独立したプロジェクトです。上の例で使ったゲートウェイ:www.china-aiapi.com(API ルート https://api.china-aiapi.com/v1)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?