Repository: open-compass/opencompass
Issue: [Bug] 测试 Claude 调用API失败
Root cause: Configuration Error

### 先决条件

- [x] 我已经搜索过 [问题](https://github.com/open-compass/opencompass/issues/) 和 [讨论](https://github.com/open-compass/opencompass/discussions) 但未得到预期的帮助。
- [x] 错误在 [最新版本](https://github.com/open-compass/opencompass) 中尚未被修复。

### 问题类型

我正在使用官方支持的任务/模型/数据集进行评估。

### 环境

# python -c "import opencompass.utils;import pprint;pprint.pprint(dict(opencompass.utils.collect_env()))"
{'CUDA available': False,
 'GCC': 'gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0',
 'MMEngine': '0.10.7',
 'MUSA available': False,
 'OpenCV': '4.11.0',
 'PyTorch': '2.8.0+cu128',
 'PyTorch compiling details': 'PyTorch built with:\n'
                              '  - GCC 13.3\n'
                              '  - C++ Version: 201703\n'
                              '  - Intel(R) oneAPI Math Kernel Library Version '
                              '2024.2-Product Build 20240605 for Intel(R) 64 '
                              'architecture applications\n'
                              '  - Intel(R) MKL-DNN v3.7.1 (Git Hash '
                              '8d263e693366ef8db40acc569cc7d8edf644556d)\n'
                              '  - OpenMP 201511 (a.k.a. OpenMP 4.5)\n'
                              '  - LAPACK is enabled (usually provided by '
                              'MKL)\n'
                              '  - NNPACK is enabled\n'
                              '  - CPU capability usage: AVX2\n'
                              '  - Build settings: BLAS_INFO=mkl, '
                              'BUILD_TYPE=Release, '
                              'COMMIT_SHA=a1cb3cc05d46d198467bebbb6e8fba50a325d4e7, '
                              'CUDA_VERSION=12.8, CUDNN_VERSION=9.8.0, '
                              'CXX_COMPILER=/opt/rh/gcc-toolset-13/root/usr/bin/c++, '
                              'CXX_FLAGS= -fvisibility-inlines-hidden '
                              '-DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO '
                              '-DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON '
                              '-DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK '
                              '-DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE '
                              '-O2 -fPIC -DC10_NODEPRECATED -Wall -Wextra '
                              '-Werror=return-type -Werror=non-virtual-dtor '
                              '-Werror=range-loop-construct '
                              '-Werror=bool-operation -Wnarrowing '
                              '-Wno-missing-field-initializers '
                              '-Wno-unknown-pragmas -Wno-unused-parameter '
                              '-Wno-strict-overflow -Wno-strict-aliasing '
                              '-Wno-stringop-overflow -Wsuggest-override '
                              '-Wno-psabi -Wno-error=old-style-cast '
                              '-faligned-new -Wno-maybe-uninitialized '
                              '-fno-math-errno -fno-trapping-math '
                              '-Werror=format -Wno-dangling-reference '
                              '-Wno-error=dangling-reference '
                              '-Wno-stringop-overflow, LAPACK_INFO=mkl, '
                              'PERF_WITH_AVX=1, PERF_WITH_AVX2=1, '
                              'TORCH_VERSION=2.8.0, USE_CUDA=ON, USE_CUDNN=ON, '
                              'USE_CUSPARSELT=1, USE_GFLAGS=OFF, USE_GLOG=OFF, '
                              'USE_GLOO=ON, USE_MKL=ON, USE_MKLDNN=ON, '
                              'USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, '
                              'USE_OPENMP=ON, USE_ROCM=OFF, '
                              'USE_ROCM_KERNEL_ASSERT=OFF, USE_XCCL=OFF, '
                              'USE_XPU=OFF, \n',
 'Python': '3.10.18 (main, Jun  5 2025, 13:14:17) [GCC 11.2.0]',
 'lmdeploy': "not installed:No module named 'lmdeploy'",
 'numpy_random_seed': 2147483648,
 'opencompass': '0.5.0+190cc0c',
 'sys.platform': 'linux',
 'transformers': '4.56.1'}

### 重现问题 - 代码/配置示例

<!-- Failed to upload "QQ_1762344100744.png" -->

# export ANTHROPIC_BASE_URL="https://api.ezclaude.com/v1"                         
# echo $ANTHROPIC_BASE_URL       
https://api.ezclaude.com/v1

# cat  claude2-test.py
from opencompass.models.claude_api.claude_api import Claude
from opencompass.utils.text_postprocessors import last_option_postprocess, first_option_postprocess
from opencompass.models.claude_api.postprocessors import (yes_no_postprocess, humaneval_claude2_postprocess, record_postprocess,
                                                          gsm8k_postprocess, strategyqa_pred_postprocess, mbpp_postprocess,
                                                          lcsts_postprocess)


agieval_single_choice_sets = [
    'gaokao-chinese',
    'gaokao-english',
    'gaokao-geography',
    'gaokao-history',
    'gaokao-biology',
    'gaokao-chemistry',
    'gaokao-mathqa',
    'logiqa-zh',
    'lsat-ar',
    'lsat-lr',
    'lsat-rc',
    'logiqa-en',
    'sat-math',
    'sat-en',
    'sat-en-without-passage',
    'aqua-rat',
]
agieval_multiple_choices_sets = [
    'gaokao-physics',
    'jec-qa-kd',
    'jec-qa-ca',
]

claude_postprocessors = {
    'ceval-*': dict(type=last_option_postprocess, options='ABCD'),
    'bustm-*': dict(type=last_option_postprocess, options='AB'),
    'summedits': dict(type=last_option_postprocess, options='AB'),
    'WiC': dict(type=last_option_postprocess, options='AB'),
    'gsm8k': dict(type=gsm8k_postprocess),
    'openai_humaneval': dict(type=humaneval_claude2_postprocess),
    'lcsts': dict(type=lcsts_postprocess),
    'mbpp': dict(type=mbpp_postprocess),
    'strategyqa': dict(type=strategyqa_pred_postprocess),
    'WSC': dict(type=yes_no_postprocess),
    'BoolQ': dict(type=yes_no_postprocess),
    'cmnli': dict(type=first_option_postprocess, options='ABC'),
    'ocnli_fc-*': dict(type=first_option_postprocess, options='ABC'),
    'MultiRC': dict(type=yes_no_postprocess),
    'ReCoRD': dict(type=record_postprocess),
    'commonsense_qa': dict(type=last_option_postprocess, options='ABCDE'),
}

for _name in agieval_multiple_choices_sets + agieval_single_choice_sets:
    claude_postprocessors[f'agieval-{_name}'] = dict(type=last_option_postprocess, options='ABCDE')

models = [
    dict(**abbr='Claude Sonnet 4.5',
        type=Claude,
        path='Claude-Sonnet-4.5',
        key='KEY',**
        query_per_second=1,
        max_out_len=2048, max_seq_len=2048, batch_size=2,
        pred_postprocessor=claude_postprocessors,
    ),
]

### 重现问题 - 命令或脚本

# HF_DATASETS_OFFLINE=1 TRANSFORMERS_OFFLINE=1 HF_EVALUATE_OFFLINE=1 HF_HUB_OFFLINE=1 python run.py --models claude2-test.py --datasets ceval_gen --debug


### 重现问题 - 错误信息

1/05 19:57:18 - OpenCompass - INFO - Loading ceval_gen: /root/opencompass/opencompass/configs/./datasets/ceval/ceval_gen.py
11/05 19:57:18 - OpenCompass - INFO - Loading claude2-test: /root/opencompass/opencompass/configs/./models/claude/claude2-test.py
11/05 19:57:18 - OpenCompass - INFO - Loading example: /root/opencompass/opencompass/configs/./summarizers/example.py
11/05 19:57:18 - OpenCompass - INFO - Current exp folder: outputs/default/20251105_195718
11/05 19:57:18 - OpenCompass - WARNING - SlurmRunner is not used, so the partition argument is ignored.
11/05 19:57:18 - OpenCompass - INFO - Partitioned into 1 tasks.
11/05 19:57:21 - OpenCompass - INFO - Task [Claude Sonnet 4.5/ceval-probability_and_statistics,Claude Sonnet 4.5/ceval-discrete_mathematics,Claude Sonnet 4.5/ceval-high_school_mathematics]
Map: 100%|███████████████████████████████| 5/5 [00:00<00:00, 1149.44 examples/s]
Map: 100%|█████████████████████████████| 18/18 [00:00<00:00, 3736.39 examples/s]
Map: 100%|███████████████████████████| 166/166 [00:00<00:00, 9649.83 examples/s]
11/05 19:57:21 - OpenCompass - INFO - Start inferencing [Claude Sonnet 4.5/ceval-probability_and_statistics]
100%|███████████████████████████████████████| 18/18 [00:00<00:00, 543147.28it/s]
[2025-11-05 19:57:21,600] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting build dataloader
[2025-11-05 19:57:21,600] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting inference process...
  0%|                                                     | 0/9 [00:00<?, ?it/s]11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
  0%|                                                     | 0/9 [00:03<?, ?it/s]
Traceback (most recent call last):
  File "/root/opencompass/run.py", line 4, in <module>
    main()
  File "/root/opencompass/opencompass/cli/main.py", line 354, in main
    runner(tasks)
  File "/root/opencompass/opencompass/runners/base.py", line 38, in __call__
    status = self.launch(tasks)
  File "/root/opencompass/opencompass/runners/local.py", line 128, in launch
    task.run(cur_model=getattr(self, 'cur_model',
  File "/root/opencompass/opencompass/tasks/openicl_infer.py", line 90, in run
    self._inference()
  File "/root/opencompass/opencompass/tasks/openicl_infer.py", line 140, in _inference
    inferencer.inference(retriever,
  File "/root/opencompass/opencompass/openicl/icl_inferencer/icl_gen_inferencer.py", line 153, in inference
    results = self.model.generate_from_template(
  File "/root/opencompass/opencompass/models/base.py", line 201, in generate_from_template
    return self.generate(inputs, max_out_len=max_out_len, **kwargs)
  File "/root/opencompass/opencompass/models/claude_api/claude_api.py", line 70, in generate
    results = list(
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 621, in result_iterator
    yield _result_or_cancel(fs.pop())
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 319, in _result_or_cancel
    return fut.result(timeout)
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/opencompass/opencompass/models/claude_api/claude_api.py", line 117, in _generate
    raise RuntimeError('Calling Claude API failed after retrying for '
RuntimeError: Calling Claude API failed after retrying for 2 times. Check the logs for details.

### 其他信息

1/05 19:57:18 - OpenCompass - INFO - Loading ceval_gen: /root/opencompass/opencompass/configs/./datasets/ceval/ceval_gen.py
11/05 19:57:18 - OpenCompass - INFO - Loading claude2-test: /root/opencompass/opencompass/configs/./models/claude/claude2-test.py
11/05 19:57:18 - OpenCompass - INFO - Loading example: /root/opencompass/opencompass/configs/./summarizers/example.py
11/05 19:57:18 - OpenCompass - INFO - Current exp folder: outputs/default/20251105_195718
11/05 19:57:18 - OpenCompass - WARNING - SlurmRunner is not used, so the partition argument is ignored.
11/05 19:57:18 - OpenCompass - INFO - Partitioned into 1 tasks.
11/05 19:57:21 - OpenCompass - INFO - Task [Claude Sonnet 4.5/ceval-probability_and_statistics,Claude Sonnet 4.5/ceval-discrete_mathematics,Claude Sonnet 4.5/ceval-high_school_mathematics]
Map: 100%|███████████████████████████████| 5/5 [00:00<00:00, 1149.44 examples/s]
Map: 100%|█████████████████████████████| 18/18 [00:00<00:00, 3736.39 examples/s]
Map: 100%|███████████████████████████| 166/166 [00:00<00:00, 9649.83 examples/s]
11/05 19:57:21 - OpenCompass - INFO - Start inferencing [Claude Sonnet 4.5/ceval-probability_and_statistics]
100%|███████████████████████████████████████| 18/18 [00:00<00:00, 543147.28it/s]
[2025-11-05 19:57:21,600] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting build dataloader
[2025-11-05 19:57:21,600] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting inference process...
  0%|                                                     | 0/9 [00:00<?, ?it/s]11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
11/05 19:57:24 - OpenCompass - ERROR - /root/opencompass/opencompass/models/claude_api/claude_api.py - _generate - 115 - Error code: 404
  0%|                                                     | 0/9 [00:03<?, ?it/s]
Traceback (most recent call last):
  File "/root/opencompass/run.py", line 4, in <module>
    main()
  File "/root/opencompass/opencompass/cli/main.py", line 354, in main
    runner(tasks)
  File "/root/opencompass/opencompass/runners/base.py", line 38, in __call__
    status = self.launch(tasks)
  File "/root/opencompass/opencompass/runners/local.py", line 128, in launch
    task.run(cur_model=getattr(self, 'cur_model',
  File "/root/opencompass/opencompass/tasks/openicl_infer.py", line 90, in run
    self._inference()
  File "/root/opencompass/opencompass/tasks/openicl_infer.py", line 140, in _inference
    inferencer.inference(retriever,
  File "/root/opencompass/opencompass/openicl/icl_inferencer/icl_gen_inferencer.py", line 153, in inference
    results = self.model.generate_from_template(
  File "/root/opencompass/opencompass/models/base.py", line 201, in generate_from_template
    return self.generate(inputs, max_out_len=max_out_len, **kwargs)
  File "/root/opencompass/opencompass/models/claude_api/claude_api.py", line 70, in generate
    results = list(
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 621, in result_iterator
    yield _result_or_cancel(fs.pop())
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 319, in _result_or_cancel
    return fut.result(timeout)
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 458, in result
    return self.__get_result()
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/root/anaconda3/envs/open-compass/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/opencompass/opencompass/models/claude_api/claude_api.py", line 117, in _generate
    raise RuntimeError('Calling Claude API failed after retrying for '
RuntimeError: Calling Claude API failed after retrying for 2 times. Check the logs for details.

服务端返回错误

2025-11-05 12:08:32.8079 | [INFO] | [7844.80] | [Diagnostics] | Request reached the end of the middleware pipeline without being handled by application code. Request path: POST http://api.ezclaude.com/v1/v1/complete, Response status code: 404 |

export ANTHROPIC_BASE_URL="https://api.ezclaude.com/" 
重新设置URL后

2025-11-05 10:02:21.6982 | [INFO] | [10572.53] | [Diagnostics] | Request reached the end of the middleware pipeline without being handled by application code. Request path: POST http://api.ezclaude.com/v1/complete, Response status code: 404 |


使用ClaudeSDK 解决