cursor icon indicating copy to clipboard operation
cursor copied to clipboard

API base URL

Open Louis454545 opened this issue 2 years ago • 28 comments

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

Louis454545 avatar May 30 '23 16:05 Louis454545

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?

truell20 avatar May 30 '23 20:05 truell20

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.

kidgokugoku avatar Jun 08 '23 06:06 kidgokugoku

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

truell20 avatar Jun 10 '23 20:06 truell20

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.

sanbaideng avatar Jun 12 '23 06:06 sanbaideng

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

kidgokugoku avatar Jun 13 '23 13:06 kidgokugoku

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 avatar Jun 15 '23 10:06 Water-Buckets

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.

Water-Buckets avatar Jun 15 '23 11:06 Water-Buckets

@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.

cestivan avatar Jul 01 '23 07:07 cestivan

Want to know the progress of this matter.

ddhjy avatar Jul 07 '23 07:07 ddhjy

I want this feature too~!

nbb2025 avatar Jul 13 '23 01:07 nbb2025

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

Sanger2000 avatar Jul 18 '23 04:07 Sanger2000

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.

Water-Buckets avatar Jul 19 '23 08:07 Water-Buckets

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?

byeugenius avatar Aug 04 '23 17:08 byeugenius

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!

  • For users in the EU it is difficult to use a service that has its servers in the US due to data protection rights.
  • Corporations want to build on the data protection contracts that they already have with Azure.

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

FabianHertwig avatar Aug 17 '23 12:08 FabianHertwig

Where to configure the open api base url?

Louis454545 avatar Aug 17 '23 15:08 Louis454545

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.

niieani avatar Aug 26 '23 02:08 niieani

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.

qianjunye avatar Sep 14 '23 07:09 qianjunye

@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.

pvbhanuteja avatar Sep 18 '23 03:09 pvbhanuteja

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

image image

2nthony avatar Oct 27 '23 16:10 2nthony

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. 🥲

2nthony avatar Nov 29 '23 16:11 2nthony

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

liumengdi avatar Dec 08 '23 06:12 liumengdi

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

krishna-praveen avatar Jan 23 '24 05:01 krishna-praveen

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!

im-calvin avatar Feb 24 '24 00:02 im-calvin

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

bpawnzZ avatar Apr 15 '24 09:04 bpawnzZ

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 avatar Aug 17 '24 19:08 TianzeWang

@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?

TianzeWang avatar Aug 17 '24 19:08 TianzeWang

@TianzeWang sorry

Louis454545 avatar Aug 17 '24 19:08 Louis454545

same as #909

sFritsch09 avatar Sep 05 '24 12:09 sFritsch09

https://github.com/getcursor/cursor/issues/909

jjohndrow avatar Feb 04 '25 22:02 jjohndrow

looks like my comment was deleted and tagged 909. Not exactly but fine. It has to do with a bug in the way you are handling the Azure OpenAI url which is different than wanting to use a different URL for OpenAI. I can put a url in Azure OpenAI, it just does not work if you have more than just the base URL.

jjohndrow avatar Feb 05 '25 16:02 jjohndrow