@@ -9,10 +9,7 @@ pip install replicate
99## Quick Start
1010
1111``` python
12- from replicate import Replicate
13-
14- # Initialize with REPLICATE_API_TOKEN env var by default
15- replicate = Replicate()
12+ import replicate
1613
1714# Create a model function
1815banana = replicate.use(" google/nano-banana" )
@@ -30,37 +27,45 @@ output = replicate.run(
3027
3128## Client Initialization
3229
33- ### Synchronous Client
30+ By default, the SDK uses the ` REPLICATE_API_TOKEN ` environment variable:
3431
3532``` python
36- from replicate import Replicate
33+ import replicate
3734
38- # Using environment variable (REPLICATE_API_TOKEN)
39- replicate = Replicate()
35+ # Uses REPLICATE_API_TOKEN from environment
36+ output = replicate.run(" google/nano-banana" , input = {" prompt" : " hello" })
37+ ```
38+
39+ ### Custom Client Configuration
4040
41- # With explicit token
42- replicate = Replicate(bearer_token = " your_api_token" )
41+ For advanced use cases, you can create an explicit client instance:
4342
44- # Legacy token parameter (for compatibility)
45- replicate = Replicate(api_token = " your_api_token" )
43+ ``` python
44+ from replicate import Replicate
45+ import os
4646
47- # With custom configuration
47+ # Explicitly specify which environment variable to use
4848replicate = Replicate(
49- bearer_token = " your_api_token " ,
49+ bearer_token = os.environ.get( " MY_REPLICATE_TOKEN " ) ,
5050 base_url = " https://api.replicate.com/v1" , # Optional custom base URL
5151 timeout = 120.0 , # Request timeout in seconds
5252 max_retries = 5 # Maximum number of retries
5353)
54+
55+ # Now use this configured client
56+ output = replicate.run(" google/nano-banana" , input = {" prompt" : " hello" })
5457```
5558
5659### Asynchronous Client
5760
5861``` python
5962from replicate import AsyncReplicate
6063import asyncio
64+ import os
6165
6266async def main ():
63- replicate = AsyncReplicate(bearer_token = " your_api_token" )
67+ # Can specify token explicitly if needed
68+ replicate = AsyncReplicate(bearer_token = os.environ.get(" MY_REPLICATE_TOKEN" ))
6469 output = await replicate.run(
6570 " google/nano-banana" ,
6671 input = {" prompt" : " a watercolor painting" }
@@ -664,12 +669,10 @@ The SDK respects these environment variables:
664669The SDK is fully typed with comprehensive type hints:
665670
666671``` python
667- from replicate import Replicate
672+ import replicate
668673from replicate.types import Prediction, PredictionStatus
669674from replicate.pagination import SyncCursorURLPage
670675
671- replicate: Replicate = Replicate()
672-
673676# Type hints for responses
674677prediction: Prediction = replicate.predictions.get(prediction_id = " abc123" )
675678status: PredictionStatus = prediction.status
@@ -708,6 +711,7 @@ from replicate import AsyncReplicate
708711
709712async def batch_process (prompts ):
710713 """ Process multiple prompts in parallel."""
714+ from replicate import AsyncReplicate
711715 replicate = AsyncReplicate()
712716 tasks = [
713717 replicate.run(" model:version" , input = {" prompt" : prompt})
@@ -780,9 +784,7 @@ model = replicate.models.get("google/nano-banana")
780784
781785** New (v1.0+):**
782786``` python
783- from replicate import Replicate
784-
785- replicate = Replicate()
787+ import replicate
786788
787789# Run a model
788790output = replicate.run(
@@ -802,6 +804,8 @@ model = replicate.models.get(
802804For compatibility with older code:
803805
804806``` python
807+ from replicate import Replicate
808+
805809# Old style (still supported)
806810replicate = Replicate(api_token = " your_token" )
807811
0 commit comments