Nextjs连接OPENAI 的API,请求出现错误?是否为网络问题?

Nextjs了一个openai服务,请求发现不走梯子,连接不上,有没有解决方案?

搭了个梯子用openai的api。结果发现nextjs不走梯子。梯子改为全局也不行,用终端代理命令启动服务也不行。有没有朋友知道神木原因?

GET / 200 in 2524ms
 ✓ Compiled in 237ms (581 modules)
RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET
    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
  reason: 'maxRetriesExceeded',
  errors: [
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    }
  ],
  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
    url: 'https://api.openai.com/v1/chat/completions',
    requestBodyValues: {
      model: 'gpt-3.5-turbo',
      logit_bias: undefined,
      user: undefined,
      max_tokens: undefined,
      temperature: undefined,
      top_p: undefined,
      frequency_penalty: undefined,
      presence_penalty: undefined,
      seed: undefined,
      messages: [Array],
      tool_choice: [Object],
      tools: [Array]
    },
    statusCode: undefined,
    responseBody: undefined,
    cause: Error: read ECONNRESET
        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
      errno: -54,
      code: 'ECONNRESET',
      syscall: 'read'
    },
    isRetryable: true,
    data: undefined
  }
}
 ⨯ unhandledRejection: RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET
    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
  reason: 'maxRetriesExceeded',
  errors: [
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    }
  ],
  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
    url: 'https://api.openai.com/v1/chat/completions',
    requestBodyValues: {
      model: 'gpt-3.5-turbo',
      logit_bias: undefined,
      user: undefined,
      max_tokens: undefined,
      temperature: undefined,
      top_p: undefined,
      frequency_penalty: undefined,
      presence_penalty: undefined,
      seed: undefined,
      messages: [Array],
      tool_choice: [Object],
      tools: [Array]
    },
    statusCode: undefined,
    responseBody: undefined,
    cause: Error: read ECONNRESET
        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
      errno: -54,
      code: 'ECONNRESET',
      syscall: 'read'
    },
    isRetryable: true,
    data: undefined
  }
}
 ⨯ unhandledRejection: RetryError [AI_RetryError]: Failed after 3 attemps. Last error: Cannot connect to API: read ECONNRESET
    at _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:718:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
    at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
    at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
  reason: 'maxRetriesExceeded',
  errors: [
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    },
    APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
        at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
        at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
        at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
        at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
        at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
      url: 'https://api.openai.com/v1/chat/completions',
      requestBodyValues: [Object],
      statusCode: undefined,
      responseBody: undefined,
      cause: [Error],
      isRetryable: true,
      data: undefined
    }
  ],
  lastError: APICallError [AI_APICallError]: Cannot connect to API: read ECONNRESET
      at postToApi (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:398:15)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async OpenAIChatLanguageModel.doGenerate (webpack-internal:///(rsc)/./node_modules/ai/openai/dist/index.mjs:783:22)
      at async _retryWithExponentialBackoff (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:706:12)
      at async experimental_generateObject (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:839:30)
      at async taskManager (webpack-internal:///(rsc)/./lib/agents/task-manager.tsx:13:20)
      at async processEvents (webpack-internal:///(rsc)/./app/action.tsx:55:29) {
    url: 'https://api.openai.com/v1/chat/completions',
    requestBodyValues: {
      model: 'gpt-3.5-turbo',
      logit_bias: undefined,
      user: undefined,
      max_tokens: undefined,
      temperature: undefined,
      top_p: undefined,
      frequency_penalty: undefined,
      presence_penalty: undefined,
      seed: undefined,
      messages: [Array],
      tool_choice: [Object],
      tools: [Array]
    },
    statusCode: undefined,
    responseBody: undefined,
    cause: Error: read ECONNRESET
        at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
        at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
      errno: -54,
      code: 'ECONNRESET',
      syscall: 'read'
    },
    isRetryable: true,
    data: undefined
  }
}
阅读 995
1 个回答

可以用nginx反代openai的地址,然后nextjs访问nginx的地址,亲测有效。

推荐问题