如何在 Claude API 中使用 IPWO 代理
最后更新于
这有帮助吗?
这有帮助吗?
pip install anthropic httpxnpm install @anthropic-ai/sdk https-proxy-agentfrom anthropic import Anthropic
import httpx
proxy_url = "http://username:password@us.ipwo.net:7878"
http_client = httpx.Client(
proxy=proxy_url
)
client = Anthropic(
api_key="YOUR_CLAUDE_API_KEY",
http_client=http_client
)
response = client.messages.create(
model="claude-sonnet-4-0",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello Claude"
}
]
)
print(response.content[0].text)import asyncio
import httpx
from anthropic import AsyncAnthropic
proxy_url = "http://username:password@us.ipwo.net:7878"
async def main():
http_client = httpx.AsyncClient(
proxy=proxy_url
)
client = AsyncAnthropic(
api_key="YOUR_CLAUDE_API_KEY",
http_client=http_client
)
response = await client.messages.create(
model="claude-sonnet-4-0",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello Claude"
}
]
)
print(response.content[0].text)
asyncio.run(main())import Anthropic from "@anthropic-ai/sdk";
import { HttpsProxyAgent } from "https-proxy-agent";
const proxyAgent = new HttpsProxyAgent(
"http://username:password@us.ipwo.net:7878"
);
const anthropic = new Anthropic({
apiKey: process.env.CLAUDE_API_KEY,
httpAgent: proxyAgent
});
const response = await anthropic.messages.create({
model: "claude-sonnet-4-0",
max_tokens: 1024,
messages: [
{
role: "user",
content: "Hello Claude"
}
]
});
console.log(response.content[0].text);export HTTP_PROXY=http://username:password@us.ipwo.net:7878
export HTTPS_PROXY=http://username:password@us.ipwo.net:7878set HTTP_PROXY=http://username:password@us.ipwo.net:7878
set HTTPS_PROXY=http://username:password@us.ipwo.net:7878curl -x "us.ipwo.net:7878" \
-U "username:password" \
ipinfo.iousername
password
host
port