Your friendly neighborhood AI assistant, now in Julia!
using Claude
client = ClaudeClient()
response = chat(client, "Why is Julia awesome?")
println(response.content[1].text)
# ... Because it's fast, dynamic, and now has Claude! π
- Prerequisites
- Features
- Installation
- Quick Start
- Customization
- Examples
- API Reference
- Error Handling
- Contributing
- Julia 1.6 or higher
- An Anthropic API key (Get one here)
- HTTP.jl and JSON3.jl packages
- π Simple Integration - Connect to Claude API in just a few lines
- π οΈ Tools Support - Full support for Claude's powerful tools system
- π Secure - Environment variable support for API keys
- π― Type-Safe - Fully typed structs and methods
- π Modern - Built for Claude 3.5 Sonnet and beyond
Pop open your Julia REPL and let's get started:
] add Claude
Before starting, you'll need to set up your Anthropic API key. Here's how to do it on different operating systems:
Option 1: Terminal (Temporary - current session only)
export ANTHROPIC_API_KEY='your-api-key-here'
Option 2: Shell Config (Permanent)
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.bashrc
source ~/.bashrc # Reload the config
Option 1: Command Prompt (Temporary)
set ANTHROPIC_API_KEY=your-api-key-here
Option 2: PowerShell (Temporary)
$env:ANTHROPIC_API_KEY="your-api-key-here"
Option 3: System Environment Variables (Permanent)
- Right-click on 'This PC' or 'My Computer'
- Click 'Properties' β 'Advanced system settings' β 'Environment Variables'
- Under 'User variables' click 'New'
- Variable name:
ANTHROPIC_API_KEY
- Variable value:
your-api-key-here
- Never commit your API key to version control
- Add
.env
to your.gitignore
file - Rotate your API key periodically
- Use different API keys for development and production
using Claude
# Create client (API key from environment)
client = ClaudeClient()
# Simple question
response = chat(client, "Write me a haiku about Julia")
println(response.content[1].text)
# Print formatted response
function print_response(resp)
println("\nResponse Content:")
println("----------------")
println(resp.content[1].text)
println("\nMetadata:")
println("----------------")
println("Model: ", resp.model)
println("Tokens Used: ", resp.usage.output_tokens)
end
messages = [
Message("user", "What's the best programming language?"),
Message("assistant", "That depends on your needs! What kind of project are you working on?"),
Message("user", "I need something fast for scientific computing")
]
response = chat(client, messages)
# API health check function
function check_api_health(client)
resp = chat(client, "Hello!")
println("β API is working")
println("β Model: ", resp.model)
println("β Message ID: ", resp.id)
end
# Error handling function
function handle_error(e)
msg = string(e)
if occursin("credit balance", msg)
println("β οΈ Credit balance too low")
elseif occursin("API key", msg)
println("β οΈ API key issue")
else
println("β οΈ Error: ", e)
end
end
# Using both together
try
check_api_health(client)
response = chat(client, "Hello!")
print_response(response)
catch e
handle_error(e)
end
# Custom configuration
client = ClaudeClient(
model="claude-3-5-sonnet-20241022", # Choose your model
max_tokens=1024, # Set token limit
base_url="https://api.anthropic.com/v1" # Custom endpoint
)
# Update API key
update_api_key!(client, "your-new-key")
ClaudeClient(;
api_key::Union{String,Nothing}=nothing,
model::String="claude-3-5-sonnet-20241022",
max_tokens::Int=1024,
tools::Vector{Tool}=Tool[],
base_url::String="https://api.anthropic.com/v1"
)
Message(role::String, content::String)
The response object contains:
content
: Array of message content objectstext
: The actual response text
model
: The model usedusage
: Token usage statisticsid
: Unique message identifier
-
Credit Balance Errors
- "Insufficient credit balance"
-
API Key Errors
- Invalid/expired API key
- Missing API key
-
Rate Limit Errors
- Too many requests
-
Environment Variables
- Store API key securely
- Use
.env
files for development
-
Error Handling
- Always use try-catch blocks(for test uses)
- Handle specific error cases
- Provide clear error messages
-
Resource Management
- Monitor token usage
- Handle rate limits gracefully
- Check API health regularly
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -am 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT License - feel free to use this package to chat with Claude to your heart's content! β€οΈ
- Thanks to Anthropic for creating Claude
- Inspired by the amazing Julia community
- Built with β€οΈ and Julia