Skip to content
Merged
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
26 changes: 26 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func NewClient(authToken string) *Client {
}
}

// NewClientWithTransport creates new OpenAI API client with the provided http.Client.
func NewClientWithTransport(authToken string, transport *http.Client) *Client {
return &Client{
BaseURL: apiURLv1,
HTTPClient: transport,
authToken: authToken,
idOrg: "",
}
}

// NewOrgClient creates new OpenAI API client for specified Organization ID.
func NewOrgClient(authToken, org string) *Client {
return &Client{
Expand All @@ -40,6 +50,22 @@ func NewOrgClient(authToken, org string) *Client {
}
}

// NewOrgClientWithTransport creates new OpenAI API client for specified Organization ID with the provided http.Client.
func NewOrgClientWithTransport(authToken, org string, transport *http.Client) *Client {
return &Client{
BaseURL: apiURLv1,
HTTPClient: transport,
authToken: authToken,
idOrg: org,
}
}

// WithTransport returns the OpenAI API client configured to use the provided http.Client.
func (c *Client) WithTransport(transport *http.Client) *Client {
c.HTTPClient = transport
return c
}

func (c *Client) sendRequest(req *http.Request, v interface{}) error {
req.Header.Set("Accept", "application/json; charset=utf-8")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.authToken))
Expand Down