-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Can add custom headers? #688
Labels
enhancement
New feature or request
Comments
@zjvn you can customize it with |
I had the same problem. The following should be a quick and dirty example for how to do this.
|
Try the following code: package openai
import (
"net/http"
"strings"
)
// DefaultHeaderTransport is an http.RoundTripper that adds the given headers to
type DefaultHeaderTransport struct {
Origin http.RoundTripper
Header http.Header
}
// RoundTrip implements the http.RoundTripper interface.
func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
for key, values := range t.Header {
for _, value := range values {
req.Header.Add(key, value)
}
}
return t.Origin.RoundTrip(req)
}
// NewHeaders creates a new http.Header from the given slice of headers.
func NewHeaders(headers []string) http.Header {
h := make(http.Header)
for _, header := range headers {
// split header into key and value with = as delimiter
vals := strings.Split(header, "=")
if len(vals) != 2 {
continue
}
h.Add(vals[0], vals[1])
}
return h
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use a third party proxy for openai and they require some custom headers to verify my identity.
Some third parties that process OpenAI may require additional headers to perform some verification on the basis of complying with OpenAI rules. For example, if I preset some tools on a third-party platform, I need to specify certain headers to tell him where the tools I need are.
The text was updated successfully, but these errors were encountered: