<type>documentation</type>
<domain>ai</domain>
<id>provider</id>
<title>Configuring AI Providers</title>
<date>$Date: 2006-05-24 22:53:07 -0400 (Wed, 24 May 2006) $</date>
<version>$Revision: 13098 $</version>
<product>pro+</product>

To protect your data, AI-assisted development is disabled by default and needs to be configured
independently in each of your Wing Pro projects before it will work. You also need to explicitly
approve uploading content to the AI provider. Unless both these steps are taken, the AI integration
will not work and no content will ever be uploaded to the AI provider. This design allows you to use
AI in some projects, while avoiding it entirely in projects where privacy or other concerns prevent
its use. See also `AI Assisted Development Privacy and Data Protection <ref:ai/privacy>`__.

Wing currently supports `OpenAI <https://openai.com/>`__, `Gemini <https://gemini.google.com/>`__,
`Grok <https://grok.com/>`__, `Perplexity <https://www.perplexity.ai/>`__, `Claude
<https://claude.ai/>`__, `Mistral <https://mistral.ai/>`__, and `Deepseek
<https://www.deepseek.com/>`__ as AI providers, as well as any other provider that implements an
OpenAI compatible completions API. In order to use AI in Wing, you must have your own account and
API key with your selected AI provider. Some AI providers offer a free usage tier, but in many cases
you will need to purchase API credits in order to gain access to more capable AI models or to lift
rate limits. If you find that you are getting poor results, this may be due to the limitations on
the freely available models. AI is very compute and energy intensive so it's not surprising that the
free models are rather limited in their abilities.

Wing will prompt you to configure an AI provider the first time you try to use any AI feature, or
you can do it from ``Manage Providers`` in the ``AI`` menu. 

**Provider Configuration**

To create an AI provider configuration, select ``Manage AI Providers`` from the ``AI`` menu and
press the ``+`` icon.

On the ``Provider`` tab of your AI provider configuration, you will need to enter a name for the
configuration, select the AI provider to use, specify the API key, and select the language model to
use. Depending on the model chosen, you should also configure the currency and token costs to match
what you are being charged by your AI provider, so that you can keep track of the cost of requests
that you make from Wing.

You will need to log into your AI provider account to generate your API key. The key can be placed
into a file (the default location in your `User Settings <ref:install/user-settings-dir>`__ directory
is given in the dialog) or enter it directly under ``Use Key``. We recommend using a file so the the
key is less likely to be shared accidentally and so you can more easily reuse it in other AI
provider configurations. If you do enter your API key directly, it will be written to the ``.wpu``
user and machine specific branch of your project, which typically should not be shared because it is
intended only for the local environment.

Once you save your first AI provider configuration, Wing will start to use it. However, it will not
upload any data to the provider until you have also approved content uploads. You will be asked to
approve uploads the first time you use the AI provider, or you can select ``Approve Uploads to
OpenAI`` in the ``AI`` menu. Once this is done, you can use ``Revoke Upload Permissions`` in the
``AI`` menu at any time to prevent further content uploads.

**Context Configuration**

The ``Context`` tab of the AI provider configuration allows you to configure thresholds for how
much context Wing will upload with your AI request.  The values used here depende on the capabilities 
of the AI language model that you have selected:

* ``Max Context Unit Size (KB)`` sets the maximum number of kilobytes of code from any given file
  that may be submitted with an AI request.

* ``Max Total Context Size (KB)`` sets the maximum size in kilobytes of all context that may be
  submitted with an AI request. This includes context from the current file, any manually specified
  context, and files selected by automatic context options.

* ``Max Upload Size (KB)`` sets the maximum total size in kilobytes of all files that may be
  uploaded to the AI provider at any given time.

* ``Max Upload File Count`` sets the maximum number of files that may be uploaded to the AI provider
  at any given time.

The maximum sizes to use here are governed by the capabilities of your AI provider and language
model, the specific rate limits imposed by your AI provider account, and the cost of requests. Note,
however, that the upper limit may never be reached if your files are small and/or you have not
enabled the use of additional context.

It may take some experimentation to find the best value to use, where enough context is
provided for quality results without overwhelming the AI provider or running into your
account's rate limits.

**Testing the Configuration**

To test your configuration, open the ``AI Chat`` tool from the ``AI`` menu, enter "Can you write
a Python hello world?", and press the ``Send`` button.  You should see a ``Waiting`` message appear 
at the bottom of the ``AI Chat`` tool. When the operation completes the result will appear in the
``AI Chat`` tool.

If this doesn't work, select ``Show Console`` in the ``AI Chat`` tool's Options`` menu. The console
shows everything Wing sends to the AI provider and all responses and error messages.

