Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring OpenAI API URL and API key #4316

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-forks-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/ai-openai": patch
---

Allow configuring OpenAI API URL and API key in OpenAI client constructor
13 changes: 8 additions & 5 deletions packages/ai/openai/src/OpenAiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export declare namespace OpenAiClient {
* @category constructors
*/
export const make = (options: {
readonly apiKey: Redacted.Redacted
readonly apiKey?: Redacted.Redacted | undefined
readonly apiUrl?: string | undefined
readonly organizationId?: Redacted.Redacted | undefined
readonly projectId?: Redacted.Redacted | undefined
readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient
Expand All @@ -64,8 +65,8 @@ export const make = (options: {
const httpClient = (yield* HttpClient.HttpClient).pipe(
HttpClient.mapRequest((request) =>
request.pipe(
HttpClientRequest.prependUrl("https://api.openai.com/v1"),
HttpClientRequest.bearerToken(options.apiKey),
HttpClientRequest.prependUrl(options.apiUrl ?? "https://api.openai.com/v1"),
options.apiKey ? HttpClientRequest.bearerToken(options.apiKey) : identity,
options.organizationId !== undefined
? HttpClientRequest.setHeader("OpenAI-Organization", Redacted.value(options.organizationId))
: identity,
Expand Down Expand Up @@ -153,7 +154,8 @@ export const make = (options: {
* @category layers
*/
export const layer = (options: {
readonly apiKey: Redacted.Redacted
readonly apiKey?: Redacted.Redacted | undefined
readonly apiUrl?: string | undefined
readonly organizationId?: Redacted.Redacted | undefined
readonly projectId?: Redacted.Redacted | undefined
readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient
Expand All @@ -165,7 +167,8 @@ export const layer = (options: {
*/
export const layerConfig = (
options: Config.Config.Wrap<{
readonly apiKey: Redacted.Redacted
readonly apiKey?: Redacted.Redacted | undefined
readonly apiUrl?: string | undefined
readonly organizationId?: Redacted.Redacted | undefined
readonly projectId?: Redacted.Redacted | undefined
readonly transformClient?: (client: HttpClient.HttpClient) => HttpClient.HttpClient
Expand Down
Loading