# HostAI class
{: .no_toc }

The IDE's AI models, for an add-in to hold conversations with. Reached through [**Host.AI**](/tB/Packages/tbIDE/Host.md#ai).

The models are those the user lists in the **AI** group of [IDE Options](/tB/IDE/Customising/IDE-Options.md#ai-models), each an endpoint of an AI service, an API key and a model's name. An add-in gets them as providers, starts a conversation with one, and has the IDE send the conversation's messages to the service. The add-in never sees the endpoint or the key.

```tb check_build
Private WithEvents Chat As AIConversation

Private Sub Host_OnProjectLoaded()
    If Host.AI.Providers.Count = 0 Then
        Host.ShowNotification "No AI model is set up in IDE Options."
        Exit Sub
    End If
    Set Chat = Host.AI.Providers.DefaultProvider.StartConversation()
    Chat.SystemPrompt = "Answer in one sentence."
    Chat.Ask "What is twinBASIC?", False
End Sub

Private Sub Chat_Completed(ByVal Response As String)
    Host.DebugConsole.PrintText Response
End Sub

Private Sub Chat_Failed(ByVal ErrorMessage As String)
    Host.DebugConsole.PrintText "The AI failed: " & ErrorMessage
End Sub
```

* TOC
{:toc}

## Properties

### Providers
{: .no_toc }

The models that the IDE's options list and enable. **As** [**HostAIProviders**](/tB/Packages/tbIDE/HostAIProviders.md), read-only.

## See Also

- [Host.AI](/tB/Packages/tbIDE/Host.md#ai) property
- [HostAIProviders](/tB/Packages/tbIDE/HostAIProviders.md) class
- [AIConversation](/tB/Packages/tbIDE/AIConversation.md) class
- [IDE Options](/tB/IDE/Customising/IDE-Options.md#ai-models) -- where the user lists the models
