Overview
Some providers require authentication or cookies to access their API. This guide will show you how to set cookies and authenticate with these providers in theg4f
package.
Setting Cookies
Setting Cookies for a Provider
Setting Cookies for a Provider
Authentication
Authenticating with a Provider
Authenticating with a Provider
Some providers like OpenAI require an access token for authentication. You can pass the access token when creating a completion:Use the
auth
parameter and provide your access token as a string.Automatically Reading Cookies
Automatically Reading Cookies
Troubleshooting
Cookies Not Being Set
Cookies Not Being Set
Authentication Errors
Authentication Errors
If you encounter authentication errors, double check that:
- Your access token is valid and not expired
- You are passing the token in the
auth
parameter - The provider supports authentication via access tokens
Example
Here’s an example of setting cookies and using authentication:Conclusion
Adding cookies and authentication is straightforward with theg4f
package. Use the set_cookies
function to manually set cookies or let the package automatically read them from your browser. For providers needing authentication, pass your access token using the auth
parameter.