Skip to content

AI gateway not injecting API key #348

@jsw324

Description

@jsw324

From a fresh v1 project, upgraded to the latest SDK, i added a simple Anthropic and OpenAI inference call and both failed with a missing API key error

Example code:

src/agent/hello/agent.ts

import { createAgent } from '@agentuity/runtime';
import { s } from '@agentuity/schema';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const agent = createAgent('hello', {
	description: 'This is my first agent ✨',
	schema: {
		input: s.object({ name: s.string() }),
		output: s.string(),
	},
	handler: async (_c, { name }) => {
		const { text } = await generateText({
		model: openai('gpt-5-mini'),
		prompt: name,
		});
		return text;
	},
});

export default agent;

Returns the following error:

[ERROR] LoadAPIKeyError [AI_LoadAPIKeyError]: OpenAI API key is missing. Pass it using the 'apiKey' parameter or the OPENAI_API_KEY environment variable.
    at loadApiKey (/Users/jasonwalkow/Dev/agentuity/100test/node_modules/@ai-sdk/provider-utils/dist/index.mjs:538:11)
    at getHeaders (/Users/jasonwalkow/Dev/agentuity/100test/node_modules/@ai-sdk/openai/dist/index.mjs:5843:32)
    at doGenerate (/Users/jasonwalkow/Dev/agentuity/100test/node_modules/@ai-sdk/openai/dist/index.mjs:4305:44)
    at processTicksAndRejections (native) {
  cause: undefined,
  Symbol(vercel.ai.error): true,
  Symbol(vercel.ai.error.AI_LoadAPIKeyError): true
}

Same result when using anthropic from the @ai-sdk/anthropic package.

Metadata

Metadata

Assignees

Labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions