Claude-API icon indicating copy to clipboard operation
Claude-API copied to clipboard

add: proxies argument for Client class initializing.

Open songofhawk opened this issue 2 years ago • 1 comments

Purpose

Add proxy setting to the Claude client, the user may has no right to connect claude.ai direct directly, but can do by a proxy. So this PR add an optional parameter to init funtion of Client class, which expect a dict to specify proxies for all protocals. The format of proxy parametr is same as requests lib.

Usage

import json
import os

from claude_api import Client

cookie = os.environ.get('cookie')
if not cookie:
    raise Exception('Please set the cookie environment variable')
print(f'cookie:{cookie}')

claude_api = Client(cookie, proxies={
   'http': 'http://proxy.example.com:8080',
   'https': 'http://secureproxy.example.com:8090',
})

prompt = "Please give me an interesting python code snippet within 5 lines."
conversation = claude_api.create_new_chat()
conversation_id = conversation['uuid']

response = claude_api.send_message(prompt, conversation_id)
print(response)

songofhawk avatar Sep 16 '23 15:09 songofhawk

@KoushikNavuluri Could you review this PR, this is really useful.

jiacai2050 avatar Nov 08 '23 14:11 jiacai2050