This guide shows how to download and use files attached to prompts as context. Context files can include documentation, examples, datasets, or any other files that provide additional information to your prompts.
import osfrom baytos.claro import BaytClientclient = BaytClient(api_key=os.getenv("BAYT_API_KEY"))prompt = client.get_prompt("@workspace/my-prompt:v1")# Check if prompt has any contextif prompt.has_context(): files = prompt.get_file_contexts() print(f"This prompt has {len(files)} file(s) attached") for file in files: print(f" - {file.file_name} ({file.file_size:,} bytes)")else: print("No files attached to this prompt")
Expected output
Copy
This prompt has 2 file(s) attached - example-data.csv (15,243 bytes) - documentation.pdf (523,891 bytes)
import osfrom baytos.claro import BaytClientclient = BaytClient(api_key=os.getenv("BAYT_API_KEY"))prompt = client.get_prompt("@workspace/prompt-with-files:v1")# Get list of filesfiles = prompt.get_file_contexts()if files: file = files[0] # Get first file print(f"Downloading '{file.file_name}'...") # Download file content content = client.download_context_file(file.id) # Save to disk with open(file.file_name, 'wb') as f: f.write(content) print(f"Saved to: {file.file_name}") print(f"Size: {len(content):,} bytes")
import osfrom baytos.claro import BaytClientclient = BaytClient(api_key=os.getenv("BAYT_API_KEY"))prompt = client.get_prompt("@workspace/my-prompt:v1")files = prompt.get_file_contexts()for file in files: # Check if it's a text file if file.mime_type.startswith('text/') or file.file_name.endswith('.txt'): print(f"\nReading {file.file_name}...") # Download and decode as text content = client.download_context_file(file.id) text = content.decode('utf-8') # Display preview preview = text[:200] + "..." if len(text) > 200 else text print(preview)
import osfrom baytos.claro import BaytClientclient = BaytClient(api_key=os.getenv("BAYT_API_KEY"))prompt = client.get_prompt("@workspace/my-prompt:v1")files = prompt.get_file_contexts()for file in files: # Get signed URL (if available in file object) if hasattr(file, 'url') and file.url: print(f"{file.file_name}:") print(f" Direct URL: {file.url}") else: print(f"{file.file_name}: Use download_context_file() method")
Signed URLs are temporary and expire after a certain period. Always download files when needed rather than storing URLs.