If you are getting network timeouts in the A.I. app, please follow the trouble shooting steps below.

Timeout errors mean your device is not getting replies from the OpenAI API endpoints.

Download on the App Store

Please remain calm.

From time to time the OpenAI API servers are overloaded or otherwise having issues. You can check the current status of their systems here:
https://status.openai.com

You can also check the web interface for ChatGPT:
https://chat.openai.com

If the website tells you the systems are overloaded or offers to send you a special link to login as a Plus member, thats a good indicator that the API may be saturated as well. Especially if you are using a free trial key with your initial tokens grant.


If the OpenAI systems appear to be operational, you can try clicking on the links below to go directly to the endpoints.

If you get an error page about not providing an API key or that GET requests are not allowed - That actually means it worked.

The A.I. app makes requests to this URL for text completions:
https://api.openai.com/v1/chat/completions

This is the URL for image requests:
https://api.openai.com/v1/images/generations

Open those pages on the device where you are trying to use the A.I. app.

Refresh each page a few times to see if it opens consistently.


If clicking on the links above times out, that is probably the same problem the A.I. app is having.

Standard recommendations are to:



Check the Settings/A.I. section and confirm it has access to cellular data:




If none of these steps seem to help (and you are able to see this webpage on your device), I'm not sure what else to suggest.


The A.I. app is not doing anything unusual with its requests to the OpenAI API endpoints. If you have been able to access the links on this page, then they should be accessible in the app as well.

In an attempt to be as transparent as possible, this is the source code for the top of the function that sends the messages for text completions. Its pretty standard and I dont see where it could do anything significantly different to avoid the timeouts you may be experiencing:

func sendChatMessage(_ authenticationToken: String,_ messages: [[String: String]], 
	model: String = "gpt-3.5-turbo", temperature: Double = 1.0, maxTokens: Int = 512, 
	completions: Int = 1, completion: @escaping (Result) -> Void) {

        let url = URL(string: "https://api.openai.com/v1/chat/completions")!

        let headers = [
            "Content-Type": "application/json",
            "Authorization": "Bearer \(authenticationToken)"
        ]

        let parameters: [String: Any] = [
            "model": model,
            "messages": messages,
            "temperature": temperature,
            "max_tokens": maxTokens,
            "n": completions
        ]

        let jsonData = try! JSONSerialization.data(withJSONObject: parameters)
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        request.allHTTPHeaderFields = headers
        request.httpBody = jsonData
        
        let task = URLSession.shared.dataTask(with: request) 
...

Here is a link to the Apple documentation for that call to URLSession.shared.dataTask which is what retrieves the data:
https://developer.apple.com/documentation/foundation/
url_loading_system/fetching_website_data_into_memory

Here is the OpenAI API documentation for making text completion request. You could experiment with curl, python or other simple interactions with a computer on the same network that you are trying to use with the A.I. app:
https://platform.openai.com/docs/api-reference/completions/create


I gave ChatGPT the entire source code for the sendChatMessage function and askedit for any insight into potential timeout issues:

Me:

I have an iOS app which uses this Swift code to make requests to the OpenAI API:

    func sendChatMessage(_ authenticationToken: String,_ messages: [[String: String]], 
	model: String = "gpt-3.5-turbo", temperature: Double = 1.0, maxTokens: Int = 512, 
	completions: Int = 1, completion: @escaping (Result) -> Void) {
//... all the source code for the sendChatMessage function ...
    }

A user is reporting timeouts on their device.  I have not been able to 
reproduce the issues they report.

Given the source code above, do you think the timeout issues are coming 
from an issue with the app, or somewhere else?

ChatGPT-4:

--------------------------------------------------------------------------
It's hard to determine the exact cause of the timeout issues 
without more information, but there are several possibilities. 
Here are a few factors that could contribute to the problem:

1. Network issues: The user may be experiencing network 
connectivity issues, either on their Wi-Fi or cellular 
connection. This could cause requests to the OpenAI API to 
time out.

2. OpenAI API issues: It's possible that the OpenAI API itself is 
experiencing high traffic, leading to slower response times 
and potential timeouts. 

3. Device-specific issues: The user's device could have some 
unique configuration or limitations that are causing the timeouts. 
This could include a slow or unstable internet connection, 
low memory, or an outdated iOS version.

4. App configuration: There might be an issue with the app's 
configuration on the user's device, such as incorrect API keys 
or other settings.

To debug the issue further, you can try the following:

1. Ask the user for more information, such as their device model, 
iOS version, and network conditions at the time of the issue.

2. Add better error handling and logging in your app. For example, 
log the response times of the API calls and any errors that 
occur during the process. This will help you identify patterns and 
potential issues.

3. Consider adding a timeout setting to your URLSession configuration, 
which would allow you to control the timeout interval for requests. 
This could help you determine if increasing the timeout value resolves 
the user's issue.

4. Request feedback from other users to determine if this is an isolated 
issue or something that is affecting multiple users.

The one suggestion it has for extending the timeout is something to consider. I am worried that if users are experiencing issues that cause timeouts with the default values, its already a poor user experience and longer than Siri will wait anyway.


More information about the A.I. App is available here:
https://robertsmania.com/ai