Skip to content

Commit

Permalink
Allow specifying OpenAI-Organization header: (mckaywrigley#313)
Browse files Browse the repository at this point in the history
See https://platform.openai.com/docs/api-reference/introduction

> For users who belong to multiple organizations, you can pass a header
> to specify which organization is used for an API request. Usage from
> these API requests will count against the specified organization's
> subscription quota.
  • Loading branch information
burke authored Mar 30, 2023
1 parent 3631a5a commit ef8c1b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ Create a .env.local file in the root of the repo with your OpenAI API Key:
OPENAI_API_KEY=YOUR_KEY
```

> you can set `OPENAI_API_HOST` where access to the official OpenAI host is restricted or unavailable, allowing users to configure an alternative host for their specific needs.
> You can set `OPENAI_API_HOST` where access to the official OpenAI host is restricted or unavailable, allowing users to configure an alternative host for their specific needs.
> Additionally, if you have multiple OpenAI Organizations, you can set `OPENAI_ORGANIZATION` to specify one.
**4. Run App**

Expand Down
3 changes: 3 additions & 0 deletions pages/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const handler = async (req: Request): Promise<Response> => {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`,
...(process.env.OPENAI_ORGANIZATION && {
'OpenAI-Organization': process.env.OPENAI_ORGANIZATION,
})
},
});

Expand Down
1 change: 1 addition & 0 deletions types/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ProcessEnv {
OPENAI_API_KEY: string;
OPENAI_API_HOST?: string;
OPENAI_ORGANIZATION?: string;
}
3 changes: 3 additions & 0 deletions utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const OpenAIStream = async (
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`,
...(process.env.OPENAI_ORGANIZATION && {
'OpenAI-Organization': process.env.OPENAI_ORGANIZATION,
})
},
method: 'POST',
body: JSON.stringify({
Expand Down

0 comments on commit ef8c1b2

Please sign in to comment.