You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase函数配置OpenAI本地运行遇TypeError问题求助

Firebase本地模拟器读取OpenAI密钥报错问题

错误信息

本地运行Firebase模拟器时,openaiConfig.ts文件读取OpenAI API密钥触发如下错误:

TypeError: Cannot read properties of undefined (reading 'key')

仅本地执行firebase emulators:start时出现该问题,部署到云端后函数运行正常。

相关代码

import OpenAI from 'openai';
import * as functions from 'firebase-functions';

const openaiApiKey = functions.config().openai.key;

export const openai = new OpenAI({
    apiKey: openaiApiKey,
});

已完成配置

通过以下命令设置了环境变量:

firebase functions:config:set openai.key="MY_KEY"

依赖版本

  • firebase-admin: "^12.1.0"
  • firebase-functions: "^5.0.0"
  • openai: "^4.56.0"

内容的提问来源于stack exchange,提问作者Hora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 08:27:02