replicate/replicate-python

authentication fails when provided REPLICATE_API_TOKEN on versions 0.14.0 and greater

Mohsin-Ul-Islam opened this issue · 5 comments

on versions 0.14.0 and greater, the client gives you have not passed an authentication token.

Having the same issue with 0.15.3.

I think it's due to the Client reading the REPLICATE_API_TOKEN on library import:

https://github.com/replicate/replicate-python/blob/30e4be55f96768b9d607cc8ddddb61f5aabcb3b3/replicate/client.py#L29C18-L40

I fixed this by importing the library after the environment variables are available, e.g.

# This needs to be before the llm library imports, otherwise they won't see the loaded environment variables
load_dotenv()

import replicate

I'm experiencing the same problem too. Using the default Colab available for fine-tuning a model on my own pictures

mattt commented

@Mohsin-Ul-Islam Thanks for reporting this. I apologize for any inconvenience there.

@extrange is exactly right that this new behavior is caused by a change in how the default client is initialized at the time of import.

@thijssdaniels The Colab notebook linked from the README demonstrates how to get started with Replicate.

Some users are reporting problems with this change, so I'm looking at different ways to communicate or mitigate this problem.

@thijssdaniels i modified the notebook based on @extrange's suggestion and it now works.

You could refer to:
https://colab.research.google.com/drive/1D1MvippwX-qDm6MdUmuTJlnmCX3yIvUo?usp=sharing

changes:
Comment out the import of replicate at the start and import only after the env. variables are set.

@mattt just fyi. the README colab just state this either. Someone running the readme colab would still face this issue.

mattt commented

I just merged #170 with a change that should restore the previous behavior. Please upgrade to 0.15.4 and let me know if you're still seeing this issue. Thanks!