Skip to content

Conversation

@github-actions
Copy link

@github-actions github-actions bot commented Dec 5, 2025

Motivation

The OpenAI SDK supports dynamic API key resolution through async functions, enabling use cases like credential rotation, secret manager integration, and per-request authentication. However, our SDK currently only accepts static strings for the apiKey parameter, preventing users from leveraging these capabilities.

Resolves: #4

Public API Changes

The OpenAIModelOptions.apiKey parameter now accepts either a string or an async function:

// Before: only string supported
const model = new OpenAIModel({
  modelId: 'gpt-4o',
  apiKey: 'sk-...'
})

// After: function also supported
const model = new OpenAIModel({
  modelId: 'gpt-4o',
  apiKey: async () => await secretManager.getApiKey()
})

The change is backward compatible—all existing string-based usage continues to work without modification. The function receives no arguments and must return a Promise<string>. The OpenAI SDK invokes the function before each request and validates the returned value.

zastrowm and others added 4 commits December 4, 2025 20:47
- Add ApiKeySetter type import from 'openai/client'
- Update OpenAIModelOptions.apiKey type to accept string | ApiKeySetter
- Update TSDoc to document function-based API key usage
- Update error message to mention 'string or function' option
- Add tests for function-based API key scenarios

This enables dynamic API key management for use cases like:
- API key rotation
- Runtime credential refresh
- Fetching keys from secret managers

Resolves: #4
@zastrowm
Copy link
Owner

zastrowm commented Dec 5, 2025

/strands

update the Pull Request description. The Pull request description should:

  • Be targeted as a Senior Software already familiar with the Python & TypeScript SDK
  • Should document the public api changes, including a code sample
  • It SHOULD NOT itemize every code change - leave that to the diff
  • It should emphasize the WHY behind the change
  • It should be concise and use text more than bullet-lists

After updating the pull-request, add a new file next to AGENT.md called PR.md which has guidance to the above. Use RFC format. Then reference that file from AGENT.md, adding a task that when creating PRs it should use the PR.md guidance


For example, this PR does not need:

  • Type Definition Updates
  • Error Message Update
  • Test Coverage
  • Implementation Notes
  • Testing

sections

- Add PR.md with RFC-style pull request description guidelines
- Update AGENTS.md to reference PR.md in development workflow
- Add section 3 'Pull Request Guidelines' to workflow
- Update section numbering accordingly

These guidelines ensure PR descriptions are concise, focus on WHY
not HOW, and target senior engineers familiar with the SDK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAI can pass apiKey in clientConfig

3 participants