KoushikNavuluri / Claude-API

This project provides an unofficial API for Claude AI, allowing users to access and interact with Claude AI .
https://pypi.org/project/claude-api/
MIT License
648 stars 112 forks source link

add: proxies argument for Client class initializing. #73

Open songofhawk opened 9 months ago

songofhawk commented 9 months ago

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)
jiacai2050 commented 7 months ago

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