{ "model":"gpt-3.5-turbo", "messages":[ { "role":"system", "content":"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make sense or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information." }, { "role":"user", "content":"{{用户输入的问题或指令}}" } ], "temperature":0.7, "max_tokens":1000, "stream":false }
{ "model":"gpt-3.5-turbo", "messages":[ { "role":"system", "content":[ { "type":"text", "text":"You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make sense or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information." }, { "type":"text", "text":"其他内容" } ] }, { "role":"user", "content":"{{用户输入的问题或指令}}" } ], "temperature":0.7, "max_tokens":1000, "stream":false }
Claude Code Router正是使用这种数组的方式发送的OpenAI API请求。问题在于,并非所有OpenAI API服务提供商都兼容了content为数组的格式,这就导致可能有部分OpenAI API服务商没办法正常通过Claude Code Router转发使用。
{"level":30,"time":1758979607079,"pid":58358,"hostname":"MACBOOKAIR-MOTHRA","msg":"register transformer: content-array-to-text (no endpoint)"}
如果出现了下面这种错误,说明你的transformers写的不对,需要修改!
1
{"level":50,"time":1758979551770,"pid":58108,"hostname":"MACBOOKAIR-MOTHRA","msg":"load transformer (/Users/mothra/.claude-code-router/plugins/content_array_to_text.js) \nerror: t is not a constructor\nstack: TypeError: t is not a constructor\n at ia.registerTransformerFromConfig (/usr/local/lib/node_modules/@musistudio/claude-code-router/dist/cli.js:79015:19)\n at ia.loadFromConfig (/usr/local/lib/node_modules/@musistudio/claude-code-router/dist/cli.js:79050:33)\n at ia.initialize (/usr/local/lib/node_modules/@musistudio/claude-code-router/dist/cli.js:79029:68)"}
"request":{ "method":"POST", "headers":{}, "body":"{\"messages\":[{\"role\":\"system\",\"content\":\"You are Claude Code, Anthropic's official CLI for Claude.\\n\\nYou are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\\n\\nIMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.\\n
而添加transformer修改之前的system content部分是个数组,如下所示
1 2 3 4
"request":{ "method":"POST", "headers":{}, "body":"{\"messages\":[{\"role\":\"system\",\"content\":[{\"type\":\"text\",\"text\":\"You are Claude Code, Anthropic's official CLI for Claude.\",\"cache_control\":{\"type\":\"ephemeral\"}},{\"type\":\"text\",\"text\":\"\\nYou are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.\\n\\nIMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Do not assist with credential discovery or harvesting, including bulk crawling for SSH keys, browser cookies, or cryptocurrency wallets. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.\\n