diff --git a/api.go b/api.go index 0a7bf1584..77b0354af 100644 --- a/api.go +++ b/api.go @@ -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{ @@ -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))