Cohere ↗ 构建旨在解决现实业务挑战的 AI 模型。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere
在向 Cohere ↗ 发出请求时,将您当前使用的 URL 中的 https://api.cohere.ai/v1
替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere
。
在向 Cohere 发出请求时,确保您具有以下内容:
- 您的 AI 网关账户 ID。
- 您的 AI 网关网关名称。
- 一个有效的 Cohere API 令牌。
- 您要使用的 Cohere 模型的名称。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1/chat \ --header 'Authorization: Token {cohere_api_token}' \ --header 'Content-Type: application/json' \ --data '{ "chat_history": [ {"role": "USER", "message": "Who discovered gravity?"}, {"role": "CHATBOT", "message": "The man who is widely credited with discovering gravity is Sir Isaac Newton"} ], "message": "What year was he born?", "connectors": [{"id": "web-search"}]}'
如果使用 cohere-python-sdk
↗,这样设置您的端点:
import cohereimport os
api_key = os.getenv('API_KEY')account_id = '{account_id}'gateway_id = '{gateway_id}'base_url = f"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/cohere/v1"
co = cohere.Client( api_key=api_key, base_url=base_url,)
message = "hello world!"model = "command-r-plus"
chat = co.chat( message=message, model=model)
print(chat)
You can also use the OpenAI-compatible endpoint (/ai-gateway/chat-completion/
) to access Cohere models using the OpenAI API schema. To do so, send your requests to:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions
Specify:
{"model": "cohere/{model}"}
- @2025 Cloudflare Ubitools
- Cf Repo