@eldrforge/ai-service 0.1.19 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -851,10 +851,23 @@ registry.registerAll(tools);
851
851
  OPENAI_API_KEY=sk-... # Your OpenAI API key
852
852
 
853
853
  # Optional
854
+ OPENAI_PROJECT_ID=proj-... # OpenAI project ID (required for project-scoped API keys)
855
+ OPENAI_TIMEOUT_MS=300000 # API timeout in milliseconds (default: 300000 = 5 minutes)
854
856
  EDITOR=code --wait # Editor for interactive editing
855
857
  OPENAI_BASE_URL=https://... # Custom OpenAI API endpoint
856
858
  ```
857
859
 
860
+ **Note on Project-Scoped API Keys:**
861
+
862
+ If your API key starts with `sk-proj-`, it's a project-scoped key and you **must** set `OPENAI_PROJECT_ID`:
863
+
864
+ ```bash
865
+ export OPENAI_API_KEY=sk-proj-...
866
+ export OPENAI_PROJECT_ID=proj-YOUR_PROJECT_ID
867
+ ```
868
+
869
+ Alternatively, you can create a legacy (non-project-scoped) API key from the [OpenAI dashboard](https://platform.openai.com/api-keys) which starts with `sk-` (without the `-proj-` suffix).
870
+
858
871
  ### Model Selection
859
872
 
860
873
  Choose the appropriate model based on your needs:
package/dist/index.js CHANGED
@@ -119,9 +119,11 @@ async function createCompletion(messages, options = { model: "gpt-4o-mini" }) {
119
119
  if (isNaN(timeoutMs) || timeoutMs <= 0) {
120
120
  throw new OpenAIError("Invalid OPENAI_TIMEOUT_MS value - must be a positive number");
121
121
  }
122
+ const projectId = process.env.OPENAI_PROJECT_ID;
122
123
  openai = new OpenAI({
123
124
  apiKey,
124
- timeout: timeoutMs
125
+ timeout: timeoutMs,
126
+ ...projectId && { project: projectId }
125
127
  });
126
128
  const modelToUse = options.model || "gpt-4o-mini";
127
129
  const requestSize = JSON.stringify(messages).length;
@@ -282,8 +284,10 @@ async function transcribeAudio(filePath, options = { model: "whisper-1" }) {
282
284
  if (!apiKey) {
283
285
  throw new OpenAIError("OPENAI_API_KEY environment variable is not set");
284
286
  }
287
+ const projectId = process.env.OPENAI_PROJECT_ID;
285
288
  openai = new OpenAI({
286
- apiKey
289
+ apiKey,
290
+ ...projectId && { project: projectId }
287
291
  });
288
292
  logger2.debug("Transcribing audio file: %s", filePath);
289
293
  if (options.debug && (options.debugRequestFile || options.debugFile) && options.storage) {