openai / openai-quickstart-node

Node.js example app from the OpenAI API quickstart tutorial
https://platform.openai.com/docs/quickstart?context=node
MIT License
2.55k stars 1.99k forks source link

How to add proxy config in the request? #50

Closed yanshanlangren closed 9 months ago

yanshanlangren commented 1 year ago

Describe the feature or improvement you're requesting

I access api.openai.com via proxy. When I try to send request by submitting form in the project, application run out with error:

requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/completions (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))

I tried the URL in web browser with proxy, and got 200 response.

I read source code but did not found anywhere to add proxy config, how can I do that? Please.

Additional context

No response

luoyashuo commented 1 year ago

Are you in China?I occurs the same problem

trampboy commented 1 year ago

You can use basePath to replace https://api.openai.com/v1

for example:

import { Configuration } from "openai";

const configuration = new Configuration({
  apiKey: OPENAI_API_KEY,
 basePath: "https://closeai.deno.dev/v1",
});

https://github.com/justjavac/openai-proxy