Sitecore Stream Setup Debugging Tips and Tricks

When I was setting up the Sitecore Stream, I ran into a few issues. I would like to share some tips and tricks that helped me resolve issues.
Unknown connection string 'sitecore.aiclient.stream'
Once the Sitecore stream package is installed, this error occurs if you try to edit any item before configuring the Sitecore Stream.

Diagnosis
Looking at the Sitecore logs and the error on the popup, it's clear that it's missing the connection string.
4284 13:15:13 ERROR Application error.
Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)Nested Exception
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
at Sitecore.Web.UI.Sheer.ClientPage.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)Nested Exception
Exception: System.InvalidOperationException
Message: Unknown connection string. Name: 'sitecore.aiclient.stream'
Source: Sitecore.Kernel
at Sitecore.Configuration.DefaultSettings.GetConnectionString(String connectionStringName)
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_StreamIdentityConnectionString()
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_StreamIdentityAuthorityUrl()
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_StreamAccessToken()
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_StreamTenantEdition()
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_IsPremiumTenantEdition()
at Sitecore.AiClient.Core.Configuration.ModuleSettings.get_FeatureStreamBrandKits()
at Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.BrandKitInitialize()
at Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.OnLoad(EventArgs e)
Solution
Ensure the connection string is added for Sitecore Stream, located in the following file path "\cm.local\App_Config\ConnectionStrings.config"
<add name="sitecore.aiclient.stream" connectionString="client_id=YOUR_ID;client_secret=YOUR_SECRET;authority=https://auth.sitecorecloud.io;audience=https://api.sitecorecloud.io" />
Error in ExecuteAction
This error occurred when I was trying to execute an action in the Sitecore Stream modal pop-up.

Diagnonsis
I started looking into the logs and found the following exception stack trace
6444 13:55:43 WARN Sitecore.AiClient.Core.AppHelper | Key 'AccessToken' not found in cache.
1192 13:56:47 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientDialog.ImproveWritingClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
6444 13:56:47 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientDialog.ExecuteImproveWritingClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
6444 13:57:02 ERROR The server encountered an internal error. Please try again later.
6444 13:57:02 ERROR System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Sitecore.AiClient.Core.Services.HttpService.GetHttpWebResponse(HttpWebRequest request)
6444 13:57:02 ERROR Error in ExecuteAction
Exception: System.InvalidOperationException
Message: The server encountered an internal error. Please try again later.
Source: Sitecore.AiClient
at Sitecore.AiClient.Core.CreateVariantRecommendation.CreateVariantRecommendations(CreateVariantsRecommendationsRequest requestModel, String accessToken)
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.GenericActionClick(PredefinedPrompt predefinedPrompt)
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.ExecuteAction(Func1 actionFunc)6752 13:57:14 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientDialog.HideSpinnerEvent,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
3212 13:57:35 ERROR The server encountered an internal error. Please try again later.
3212 13:57:35 ERROR System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Sitecore.AiClient.Core.Services.HttpService.GetHttpWebResponse(HttpWebRequest request)
3212 13:57:35 ERROR Error in ExecuteAction
Exception: System.InvalidOperationException
Message: The server encountered an internal error. Please try again later.
Source: Sitecore.AiClient
at Sitecore.AiClient.Core.CreateVariantRecommendation.CreateVariantRecommendations(CreateVariantsRecommendationsRequest requestModel, String accessToken)
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.GenericActionClick(PredefinedPrompt predefinedPrompt)
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.ExecuteAction(Func1 actionFunc) 7580
13:58:20 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientDialog.GenerateClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
6752 13:58:20 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientDialog.ExecuteGenerateClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
6752 13:58:37 ERROR The server encountered an internal error. Please try again later.
6752 13:58:37 ERROR System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Sitecore.AiClient.Core.Services.HttpService.GetHttpWebResponse(HttpWebRequest request)
6752 13:58:37 ERROR Error in ExecuteAction
Exception: System.InvalidOperationException
Message: The server encountered an internal error. Please try again later.
Source: Sitecore.AiClient
at Sitecore.AiClient.Core.CreateVariantRecommendation.CreateVariantRecommendations(CreateVariantsRecommendationsRequest requestModel, String accessToken)
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.GenerateActionClick()
at Sitecore.AiClient.Core.Dialogs.AiClientDialog.ExecuteAction(Func1 actionFunc)
I also used Postman to check if I can authenticate and get a token with my api keys to the following endpoint.
https://auth.sitecorecloud.io/oauth/token
Note: The authentication endpoint is location agnostic.

Issue and Solution
The issue was with the region of my Stream instance; for some reason, it got set up in Europe rather than the US, so the API endpoint werent authenticating. Once I was able to update the endpoints in the following file cm.local\App_Config\Sitecore\AiClient\Sitecore.AiClient.config
Typically, this will not be the case; both your tenant location and Stream Instance should be in the same area. Temporarily, I updated the {RegionName} parameter in the config file to test. Sitecore Support was helpful to fix this for us.
The operation could not be completed
I got this error when I tried to do a content extraction from text.

Diagnosis
I was able to find this in the logs, which clearly states it's forbidden.
10860 15:06:31 ERROR Error while retrieving BrandKit Id
Exception: System.Exception
Message: System does not have permission to access this resource. Please contact your administrator.
Source: Sitecore.AiClient
at Sitecore.AiClient.Core.ErrorHandling.ErrorConfigurationManager.HandleException(HttpStatusCode statusCode, String message)
at Sitecore.AiClient.Core.StreamServices.BrandManagementService.GetBrandKitIdNameList(String accessToken, Int32 pageNumber, Int32 pageSize, Boolean includeDeleted, Boolean includeDraft)Nested Exception
Exception: System.Exception
Message: System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at Sitecore.AiClient.Core.Services.HttpService.GetHttpWebResponse(HttpWebRequest request)10860 15:06:31 ERROR System does not have permission to access this resource. Please contact your administrator.
9340 15:06:47 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.FixSpellingClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
10716 15:06:47 WARN The 'Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.ExecuteFixSpellingClick,Sitecore.AiClient' method is allowed by pattern rule. It is best to allow methods by attribute.
10716 15:07:03 ERROR Error in ExecuteAction
Exception: System.Exception
Message: The server encountered an internal error. Please try again later.
Source: Sitecore.AiClient
at Sitecore.AiClient.Core.ErrorHandling.ErrorConfigurationManager.HandleException(HttpStatusCode statusCode, String message)
at Sitecore.AiClient.Core.StreamServices.AbTestingService.CreateVariants(CreateVariantsRequest modelRequest, Int32 requestTimeoutMilliseconds)
at Sitecore.AiClient.Core.StreamServices.AbTestingService.CreateVariantsPredefinedPrompt(PredefinedPrompt predefinedPrompt, String fieldName, String variantFieldValue, Int32 numberOfVariants, String streamBrandKitId)
at Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.GenericActionClick(PredefinedPrompt predefinedPrompt)
at Sitecore.AiClient.Core.Dialogs.AiClientWriteDialog.ExecuteAction(Func`1 actionFunc)Nested Exception
Exception: System.Exception
Message: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Sitecore.AiClient.Core.Services.HttpService.GetHttpWebResponse(HttpWebRequest request)
Solution
The error occurs because the free version of Sitecore Stream does not support Brand Kit.