😆

GithubCopilot経由で、ClineでClaude3.7をエラー無く使う方法

2025/03/01に公開
5

(追記2025/03/04) Githubからメールが

本方法でClaude3.7を使用していたところ、Githubから、「異常なアクティビティでありCopilotアクセスが一時的に停止される可能性がある」という旨のメールが届きました。

お客様のアカウントでの最近のアクティビティが、弊社の不正使用検出システムの注意をひきました。このアクティビティには、スクリプト化されたやり取りや、故意に異常または過酷な性質を示す Copilot の使用が含まれていました。お客様のアカウントの Copilot アクセスはまだ制限されていませんが、さらに異常なアクティビティが続くと、Copilot アクセスが一時的に停止される可能性があります。
レート制限の詳細についてはお伝えできませんが、いかなる形式の過度な自動バルクアクティビティや、自動化された手段によってサーバーに過度の負荷をかけるアクティビティにも、サーバーの使用を禁止しています。
(原文)Recent activity on your account caught the attention of our abuse-detection systems. This activity included use of Copilot that was indicative of scripted interactions or of an otherwise deliberately unusual or strenuous nature. While we have not yet restricted Copilot access for your account, further anomalous activity could result in a temporary suspension of your Copilot access.`

一定期間内に90000トークンを超えたり、429エラーとなっても繰り返し出力をさせようとすると、不正検知にひっかかるとの説もあります。
https://github.com/jjleng/copilot-more/issues/34

Claude3.7でエラー出るよね

待望のClaude3.7の出現に浮かれて、早速Clineで使用したユーザーは多いと思います。
そして、期待と裏腹に毎回出てくる謎のエラーに悩まされ、結局Claude3.5に戻した方も多いと思います。

Request Failed: 400 {"error":{"message":"Model is not supported for this request.","param":"model","code":"model_not_supported","type":"invalid_request_error"}}
-悲しみのエラー-

本記事では、copilot-moreを使ってエラーを解消し、Claude3.7を使用する方法を紹介いたします。
https://github.com/jjleng/copilot-more

対象

今回、対象となるユーザーですが
Cline、Roocode など、Cline系のツールが対象となります。

また、GithubCopilotのAPI経由でClaude3.7を使用します。Proプランだと月額10ドルで使い放題なので素敵!
https://qiita.com/shimohara7192/items/e36ed7de26fdfc49321f

仕組み

現在、ClindeでGithubCopilot経由でClaude3.7のAPIを叩くと、前述したエラーが発生します。GithubCopilotがIDEからのAPIを"ブロック"していると言われています。(Chat機能は使える)

Copilot-moreを使用し、Dockerコンテナ経由でAPIを叩くことで、IDEであるとさとられず、Claude3.7を利用することができるようになります。

注意

  • GitHub Copilot の利用規約を尊重してください。
  • コーディング以外の目的でのモデルの使用は最小限に抑えてください。
  • 悪用により GitHub Copilot によって禁止されるリスクに注意してください。

copilot-more の導入

エラーを回避してClaude3.7を使用するために、copilot-moreを使用します。
https://github.com/jjleng/copilot-more

git clone などして、IDEでcopilot-more のプロジェクトファイルを開きます。

リフレッシュトークンの発行

Readmeに従っていきます。最初にリフレッシュトークンの発行
ターミナルで、curl https://github.com/login/device/code -X POST -d 'client_id=01ab8ac9400c4e429b23&scope=user:email を実行

実行すると、次のようにトークンとユーザーコードが吐き出されます
device_code='トークン'expires_in=899&interval=5&user_code='ユーザーコード'&verification_uri=https%3A%2F%2Fgithub.com%2Flogin%2Fdevice

実行後、verification_urlのGithubURLにアクセスし、上述のユーザーコードを入力して、Authorizeしてください。

Authrrizeが完了したら、ターミナルに戻り、
curl https://github.com/login/oauth/access_token -X POST -d 'client_id=CLIENT_ID&scope=user:email&device_code=YOUR_DEVICE_CODE&grant_type=urn:ietf:params:oauth:grant-type:device_code を実行するのですが、YOUR_DEVICE_CODE を先程発行したトークンに置き換えて実行します

すると、リフレッシュトークン(access_token)が出力されます
access_token=ACCESS_TOKEN&scope=user%3Aemail&token_type=bearer
このトークンを控えておいてください。

.envファイルの作成

copilot-moreのプロジェクトファイルに、.envファイルを作成します
以下のコードをコピペし、REFRESH_TOKENの内容を先程発行したリフレッシュトークンに変更して下さい。

Required settings
REFRESH_TOKEN=gho_some_token← ココを変更!

Optional settings (defaults shown)
API endpoints
CHAT_COMPLETIONS_API_ENDPOINT=https://api.individual.githubcopilot.com/chat/completions
MODELS_API_ENDPOINT=https://api.individual.githubcopilot.com/models

For enterprise users, you can set the following endpoints:
CHAT_COMPLETIONS_API_ENDPOINT=https://api.business.githubcopilot.com/chat/completions
MODELS_API_ENDPOINT=https://api.business.githubcopilot.com/models

Request settings
MAX_TOKENS=10240
TIMEOUT_SECONDS=300
EDITOR_VERSION=vscode/1.95.3

Debug settings
RECORD_TRAFFIC=false

Docker環境の構築

Docker環境の構築はWindowsだと難しいのですが、そういうところは省略します。

.envファイルに、リフレッシュトークンを記入した後、
copilot-moreのプロジェクトファイルに入って、
docker-compose up --build、を実行します

ビルドが完了したら、
docker compose up

その後、ブラウザでhttp://localhost:15432 にアクセスします。
こんな感じになってたら動いているってことなので大丈夫です

Cline でAPI設定

Clineの設定で、APIを使えるようにしていきます。
設定で、以下のようにします

  • API Provider
    • OpenAI Compatible
  • Base URL
  • API Key
    • 任意(aaaa でもOK)
  • Model
    • claude-3.7-sonnet

これで完了です!!

エラーが出た!

完了!と思いきや、エラーが発生してしましました。

app-1 | "text": "[ERROR] You did not use a tool in your previous response! Please retry with a tool use.\n\n# Reminder: Instructions for Tool Use\n\nTool uses are formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the

そういうときは、次のコードを実行すれば解決
chmod +x refresh-token.sh
./refresh-token.sh

早速実行!

できました!!!!!!!!

完走

Happy Claude3.7 Life!!

Discussion

ようやんようやん
2025-03-03 21:59:30.353 | ERROR    | copilot_more.server:stream_response:417 - API error: {"error":{"message":"The requested model is not supported.","param":"model","code":"model_not_supported","type":"invalid_request_error"}}

というエラーが出て使えなくなってました。

えいとびーとえいとびーと

試してみて、私も同じ状態です。

APIリミットレートの制限があって、自由と言うまでは使うのは厳しそうです。90000トークンあたりからエラーが出ました

ようやんようやん

On behalf of the GitHub Security team, I want to first extend our gratitude for your continued use of GitHub and for being a valued member of the GitHub community.
Recent activity on your account caught the attention of our abuse-detection systems. This activity included use of Copilot that was indicative of scripted interactions or of an otherwise deliberately unusual or strenuous nature. While we have not yet restricted Copilot access for your account, further anomalous activity could result in a temporary suspension of your Copilot access.
While I’m unable to share specifics on rate limits, we prohibit all use of our servers for any form of excessive automated bulk activity, as well as any activity that places undue burden on our servers through automated means. Please refer to our Acceptable Use Policies on this topic: https://docs.github.com/site-policy/acceptable-use-policies/github-acceptable-use-policies#4-spam-and-inauthentic-activity-on-github.
Please also refer to our Terms for Additional Products and Features for GitHub Copilot for specific terms: https://docs.github.com/site-policy/github-terms/github-terms-for-additional-products-and-features#github-copilot.
Sincerely,
GitHub Security

というメールが届きました。即BANとはなりませんでしたがエラーが出た場合はすぐに使用を止めるのが良さそうです。

あいや - aiya000あいや - aiya000

とてもいいと思うのですが、そもそもCline系経由のGitHub Copilotの使用は、アカウントごとBANされる危険性があるんですね…。
must read

えいとびーとえいとびーと

Banリスクについてですが、以前までは無料プランで月間のAPI制限は無く、使い放題でありましたがようやく月間制限が導入されたので、希望的観測ですがそのリスクは下がったと思いたいですね..