getcursor / cursor

The AI Code Editor
https://cursor.com
22.63k stars 1.45k forks source link

API base URL #635

Open Louis-htmlcss opened 1 year ago

Louis-htmlcss commented 1 year ago

How to change the API base URL to our own proxy ?

truell20 commented 1 year ago

No support for this right now, but happy to provide this as a feature. Could you say a bit more about why you need this and what you'd want the feature to look like? Is this to get around a corporate firewall?

kidgokugoku commented 1 year ago

No support for this right now, but happy to provide this as a feature. Could you say a bit more about why you need this and what you'd want the feature to look like? Is this to get around a corporate firewall?

In my case it’s not very convenient for us in China to pay for OpenAI services directly, but we can use the API provided by mirror sites.

truell20 commented 1 year ago

Ah understood. Do you know if these APIs are the same as OpenAIs?

sanbaideng commented 1 year ago

API base URL is a good (needed) feature in China.

I have the apikey , if I connect to api.openai.com directly , it is easy to get banned by openai, because the IP is in China and they don't provide service to China .

But i can build a reverse proxy in cloudflare (worker) , if CURSOR can provide a setting to using my own baseurl, my openai account is safe.

kidgokugoku commented 1 year ago

Ah understood. Do you know if these APIs are the same as OpenAIs?

they claim that there website provides a compatible API that shares the same parameters, paths, and usage as the OpenAIs

Water-Buckets commented 1 year ago

Ah understood. Do you know if these APIs are the same as OpenAIs?

Almost exactly the same. I've tested it with js and ts. It works.

Water-Buckets commented 1 year ago

This feature is really important for developers in China. On account of the following reasons:

  1. Here in China, people seldom own a credit card. So it's hard to pay for PRO or pay for the apikey of openai.

  2. Secondly, openai may ban or delete accounts of Chinese users, even if we only use api.

  3. Thirdly, api.openai.com is banned by the GFW.

Therefore, I hope this feature will be added soom. Besides, thx for the wonderful software which is really helpful.

cestivan commented 1 year ago

@truell20 In LangChain or native SDK provided by OpenAI, there is a env key called: OPENAI_API_BASE. By setting it, we can change the root path to our proxy. It is exactly what we need. Hope this helps.

ddhjy commented 1 year ago

Want to know the progress of this matter.

nbb2025 commented 1 year ago

I want this feature too~!

Sanger2000 commented 1 year ago

This feature is really important for developers in China. On account of the following reasons:

  1. Here in China, people seldom own a credit card. So it's hard to pay for PRO or pay for the apikey of openai.
  2. Secondly, openai may ban or delete accounts of Chinese users, even if we only use api.
  3. Thirdly, api.openai.com is banned by the GFW.

Therefore, I hope this feature will be added soom. Besides, thx for the wonderful software which is really helpful.

I don't think we would get to this very soon, but if this is really important, we could get it done this week

The reason I hesitate is that by default, Cursor uses dedicated compute units, meaning a faster GPT-4 than what is normally available over API. We think the experience when using this version of GPT-4 is significantly better than the API. It is also cheaper for users than paying for the API because of the dedicated compute units.

Issue 3 should be fine as all requests are routed through our US-located servers. I am not sure how to address issue 1. At the moment, how do Chinese developers pay for OpenAI API access?

If enough people agree that this is still needed in spite of my response, please let me know! We'll get it added ASAP

Water-Buckets commented 1 year ago

This feature is really important for developers in China. On account of the following reasons:

  1. Here in China, people seldom own a credit card. So it's hard to pay for PRO or pay for the apikey of openai.
  2. Secondly, openai may ban or delete accounts of Chinese users, even if we only use api.
  3. Thirdly, api.openai.com is banned by the GFW.

Therefore, I hope this feature will be added soom. Besides, thx for the wonderful software which is really helpful.

I don't think we would get to this very soon, but if this is really important, we could get it done this week

The reason I hesitate is that by default, Cursor uses dedicated compute units, meaning a faster GPT-4 than what is normally available over API. We think the experience when using this version of GPT-4 is significantly better than the API. It is also cheaper for users than paying for the API because of the dedicated compute units.

Issue 3 should be fine as all requests are routed through our US-located servers. I am not sure how to address issue 1. At the moment, how do Chinese developers pay for OpenAI API access?

If enough people agree that this is still needed in spite of my response, please let me know! We'll get it added ASAP

For issue 3, actually we don't want the requests being routed through your US-located servers. It's because some of the non-official api providers' server are located in China, which makes it easier and faster to access form China, while routing requests through your US-located servers make it hard to do so.

My idea it that you can develop a client-side http(s)-requester so that it can make requests directly from the users PC.

It's admitted that Cursor's service is fast and cheap as you've said. But the network issues(no just because GFW banning some domains, but also the latency caused by the distance between US and China) has made it a lot slower. And the $20 Cursor PRO is still limitted (I mean gpt-4) while using the custom api can get us unlimitted usage at a price that is the same as the official's.

Here in China we usually pay with Wechat or Alipay, some times with debit card(just noticed that you supported it already). But I hope see cursor PRO support Wechat (which it once did) and Alipay. We don't actually pay for the OPENAI's API, we use those third-party ones.

This feature is not that urgent so take it slow, it's all right. But we do hope to see this custom API base URL feature be added.

byeugenius commented 1 year ago

This feature is really important for developers in China. On account of the following reasons:

  1. Here in China, people seldom own a credit card. So it's hard to pay for PRO or pay for the apikey of openai.
  2. Secondly, openai may ban or delete accounts of Chinese users, even if we only use api.
  3. Thirdly, api.openai.com is banned by the GFW.

Therefore, I hope this feature will be added soom. Besides, thx for the wonderful software which is really helpful.

I don't think we would get to this very soon, but if this is really important, we could get it done this week

The reason I hesitate is that by default, Cursor uses dedicated compute units, meaning a faster GPT-4 than what is normally available over API. We think the experience when using this version of GPT-4 is significantly better than the API. It is also cheaper for users than paying for the API because of the dedicated compute units.

Issue 3 should be fine as all requests are routed through our US-located servers. I am not sure how to address issue 1. At the moment, how do Chinese developers pay for OpenAI API access?

If enough people agree that this is still needed in spite of my response, please let me know! We'll get it added ASAP

Three weeks have already passed, can you finally add this feature?

FabianHertwig commented 1 year ago

To be able to configure the OpenAI Service provided by Azure would be a similar feature that I and probably many corporate users in the EU would like to have and goes into a similar direction!

To configure it you need to set the following parameters in the Python OpenAI API package:

openai.api_key = api_key
openai.api_base = api_base
openai.api_type = api_type
openai.api_version = api_version

The values are something like this

open_ai_api_key = "bb......"
open_ai_api_type = "azure"
open_ai_api_base = "https://westeurope.api.cognitive.microsoft.com/" # Depends on the region where the service is deployed
open_ai_api_version = "2023-03-15-preview"
open_ai_engine = "gpt-35-turbo-dev" # your custom model deployment name. 

Also see: https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line&pivots=programming-language-python#create-a-new-python-application

A difficulty could be, that currently you can switch between GPT-3.5 and GPT-4 in cursor, but in Azure they could not be available and users can give the models custom names. They can also deploy the GPT-3.5-16k and GPT-4-32k variant.

https://github.com/getcursor/cursor/issues/588 is related

Louis-htmlcss commented 1 year ago

Where to configure the open api base url?

niieani commented 1 year ago

Another use case is privacy/security - we have an internal proxy of OpenAI's service for security purposes, and can only use OpenAI's APIs through that proxy.

qianjunye commented 11 months ago

Let me provide a use case. Our company has purchased Azure services. However, the keys provided by Azure are limited. To manage the keys effectively, we have set up a proxy and authentication server. We generate virtual keys for our colleagues and provide them. After the virtual key is verified on our server, the key in the request will be replaced with the actual Azure key and forwarded to Azure's openai service in Japan.

The purpose of doing this is to manage the keys and ensure efficient key usage. Additionally, we have implemented a technical solution to request Azure in Japan through a dedicated line, avoiding latency on the public network. As it is well known, the network connection from China to international servers is not very stable.

pvbhanuteja commented 11 months ago

@Sanger2000 Still looking for this feature any updates?

I generally proxy azure openai in the openai base format so that changing the model is easier. In Azure single deployment == Single model served. Proxying something like this https://github.com/pvbhanuteja/openai-azure-proxy-cf-worker to unlock all features while using Azure openai.

2nthony commented 10 months ago

just provide an option will be fine! no need to care about endpoint paths.

image image
2nthony commented 9 months ago

just provide an option will be fine! no need to care about endpoint paths.

Any updates?🤔 I think this is really useful. I am an azure openai user, without BASEURL option, I have to go to the setting to change the deployment name if I need to switch model. It is a little complex, actually. 🥲

liumengdi commented 9 months ago

This feature is really important for developers in China. On account of the following reasons:

  1. Here in China, people seldom own a credit card. So it's hard to pay for PRO or pay for the apikey of openai.
  2. Secondly, openai may ban or delete accounts of Chinese users, even if we only use api.
  3. Thirdly, api.openai.com is banned by the GFW.

Therefore, I hope this feature will be added soom. Besides, thx for the wonderful software which is really helpful.

I don't think we would get to this very soon, but if this is really important, we could get it done this week

The reason I hesitate is that by default, Cursor uses dedicated compute units, meaning a faster GPT-4 than what is normally available over API. We think the experience when using this version of GPT-4 is significantly better than the API. It is also cheaper for users than paying for the API because of the dedicated compute units.

Issue 3 should be fine as all requests are routed through our US-located servers. I am not sure how to address issue 1. At the moment, how do Chinese developers pay for OpenAI API access?

If enough people agree that this is still needed in spite of my response, please let me know! We'll get it added ASAP

I've noticed that when I input my OpenAI API Key, Cursor sends requests directly to https://api.openai.com/v1/chat/completions. This implies that not all requests are routed through Cursor's servers in the United States.

For users in China, this could potentially lead to our account being blocked by OpenAI. As a Cursor Pro user, The 500 GPT-4 requests per month that come with my Pro subscription are not sufficient for my needs, and I would like to use my own API Key.

Please add the feature that allows us to customize API base URL ,This would provide with more flexibility  or consider routing all OpenAI requests through Cursor's servers. This would help us avoid sending requests directly from China to OpenAI, thereby reducing the risk of being blocked. This is crucial for users in China.

Thanks

krishna-praveen commented 7 months ago

Why are you guys delaying to implement this basic necessary feature?

im-calvin commented 6 months ago

I was wondering what services you guys were using to create your OpenAI proxy, if you could point me to a repository that'd be great!

bpawnzZ commented 4 months ago

I was wondering what services you guys were using to create your OpenAI proxy, if you could point me to a repository that'd be great!

LiteLLM for one. And a direct service provider for would be https://openrouter.ai

I cant believe there is no update on this. Makes me question the competence of these devs. OpenAI compatible APIs are pretty common in the AI space. The fact they seem to act like we are asking for the moon is laughable

TianzeWang commented 2 weeks ago

Another example: Some LLMs provide OpenAI compatible / Claude compatible APIs, but you need to modify URL, ModelName and API Key.

It's good to have this feature and I guess there should not be much efforts to achieve this?

TianzeWang commented 2 weeks ago

@Louis-htmlcss Hi Louis, why did you mark this as completed given this feature is not fulfilled? Would you guys still consider it in the future?

Louis-htmlcss commented 2 weeks ago

@TianzeWang sorry

sFritsch09 commented 1 day ago

same as #909