CoaiaPy supports multiple methods for configuring Redis connections, with automatic support for Upstash Redis REST API credentials.
Configuration values are resolved in the following priority order (highest to lowest):
UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKENKV_REST_API_URL, KV_REST_API_TOKENKV_URL or REDIS_URLREDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_SSL./coaia.json or ~/coaia.jsonThe easiest way to configure Redis is using Upstash REST API credentials:
export UPSTASH_REDIS_REST_URL="https://your-instance.upstash.io"
export UPSTASH_REDIS_REST_TOKEN="your_token_here"
Create a .env file in your project directory:
UPSTASH_REDIS_REST_URL=https://your-instance.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token_here
For projects deployed on Vercel using Vercel KV, the following environment variables are supported:
export KV_REST_API_URL="https://your-instance.upstash.io"
export KV_REST_API_TOKEN="your_token_here"
KV_REST_API_URL=https://your-instance.upstash.io
KV_REST_API_TOKEN=your_token_here
export KV_URL="rediss://default:your_password@your-host.upstash.io:6379"
# OR
export REDIS_URL="rediss://default:your_password@your-host.upstash.io:6379"
KV_URL=rediss://default:your_password@your-host.upstash.io:6379
# OR
REDIS_URL=rediss://default:your_password@your-host.upstash.io:6379
When a URL-based environment variable (e.g., UPSTASH_REDIS_REST_URL, KV_URL, REDIS_URL) is set, CoaiaPy automatically:
https:// or rediss:// URLs, disables for http:// or redis://.UPSTASH_REDIS_REST_TOKEN, KV_REST_API_TOKEN) or password from the connection string as the Redis password.Example URL Parsing:
| URL | Host | Port | SSL | Password Source |
|---|---|---|---|---|
https://example.upstash.io |
example.upstash.io |
6379 | Yes | UPSTASH_REDIS_REST_TOKEN |
https://example.upstash.io:6380 |
example.upstash.io |
6380 | Yes | UPSTASH_REDIS_REST_TOKEN |
http://localhost:6379 |
localhost |
6379 | No | UPSTASH_REDIS_REST_TOKEN |
rediss://default:pass@host.upstash.io:6379 |
host.upstash.io |
6379 | Yes | pass (from URL) |
You can also use traditional Redis environment variables:
export REDIS_HOST="redis.example.com"
export REDIS_PORT="6379"
export REDIS_PASSWORD="your_password"
Or in .env:
REDIS_HOST=redis.example.com
REDIS_PORT=6379
REDIS_PASSWORD=your_password
For persistent configuration across all projects:
{
"jtaleconf": {
"host": "your-redis-host.example.com",
"port": 6379,
"password": "your_password",
"ssl": true
}
}
python -c "from coaiapy.coaiamodule import read_config; import json; print(json.dumps(read_config()['jtaleconf'], indent=2))"
# Store a test value with verbose output
coaia tash test_key "test_value" --verbose
# Retrieve the value with verbose output
coaia fetch test_key --verbose
Verbose Output Example:
Connecting to Redis server:
Host: your-host.upstash.io
Port: 6379
SSL: True
Password: ***word (last 4 characters shown for security)
Status: Connection established successfully
Key: test_key was just saved to memory.
These errors typically indicate an issue with your Redis connection parameters or credentials.
Use --verbose flag: Run your coaia command with --verbose to get detailed connection information. This will show you the host, port, SSL status, and masked password being used.
coaia tash MY_KEY "my value" --verbose
echo $UPSTASH_REDIS_REST_URL
echo $UPSTASH_REDIS_REST_TOKEN
echo $KV_REST_API_URL
echo $KV_REST_API_TOKEN
echo $KV_URL
echo $REDIS_URL
echo $REDIS_HOST
echo $REDIS_PORT
echo $REDIS_PASSWORD
Ensure the values match your Redis provider’s dashboard.
cat .env
Verify variable names and values. Remember that OS environment variables take precedence over .env file values.
# Extract hostname from your Redis URL or REDIS_HOST
ping your-redis-host.upstash.io
.env file, coaia.json), ensure the one you intend to use is taking precedence. The priority order is listed at the beginning of this document.pwd
ls -la .env
=file .env # Should show ASCII or UTF-8
.env file.If coaia tash --verbose shows a different host than expected:
export command in your shell profile.coaia.json files: Look for ./coaia.json and ~/coaia.json that might be overriding your intended configuration.# Create .env file
cat > .env << EOF
UPSTASH_REDIS_REST_URL=https://talented-aardvark-34524.upstash.io
UPSTASH_REDIS_REST_TOKEN=AYbcAAIncDE...
EOF
# Test connection with verbose output
coaia tash greeting "Hello, World!" --verbose
coaia fetch greeting --verbose
# Create .env file
cat > .env << EOF
KV_REST_API_URL=https://full-alpaca-12634.upstash.io
KV_REST_API_TOKEN=AaBbCcDdEeFf123456
EOF
# Test connection with verbose output
coaia tash vercel_key "Hello from Vercel KV!" --verbose
coaia fetch vercel_key --verbose
# Set environment variables
export KV_URL="rediss://default:AaBbCcDdEeFf123456@full-alpaca-12634.upstash.io:6379"
# Test connection with verbose output
coaia tash conn_string_key "Connection string test" --verbose
coaia fetch conn_string_key --verbose
# Set environment variables
export REDIS_HOST="localhost"
export REDIS_PORT="6379"
export REDIS_PASSWORD="mysecretpassword"
# Test connection with verbose output
coaia tash local_redis_key "Local Redis test" --verbose
coaia fetch local_redis_key --verbose
# Development environment (.env.development)
UPSTASH_REDIS_REST_URL=https://dev-instance.upstash.io
UPSTASH_REDIS_REST_TOKEN=dev_token
# Production environment (.env.production)
UPSTASH_REDIS_REST_URL=https://prod-instance.upstash.io
UPSTASH_REDIS_REST_TOKEN=prod_token
# Use development
cp .env.development .env
coaia fetch dev_key --verbose
# Switch to production
cp .env.production .env
coaia fetch prod_key --verbose
REDIS_* VariablesIf you’re currently using REDIS_HOST and REDIS_PASSWORD, you can:
Option 1: Continue Using Existing Variables
# These still work
export REDIS_HOST="redis.example.com"
export REDIS_PASSWORD="password"
Option 2: Migrate to Upstash Format (Recommended for Upstash users)
# Old
export REDIS_HOST="example.upstash.io"
export REDIS_PASSWORD="token123"
# New (recommended)
export UPSTASH_REDIS_REST_URL="https://example.upstash.io"
export UPSTASH_REDIS_REST_TOKEN="token123"
UPSTASH_REST_API_* VariablesIf you were using the non-standard UPSTASH_REST_API_URL and UPSTASH_REST_API_TOKEN (which were temporarily supported in a previous version), you must migrate to the correct standard variables for your platform:
Old (no longer supported):
UPSTASH_REST_API_URL=https://...
UPSTASH_REST_API_TOKEN=...
New (choose based on your provider):
For Upstash Direct:
UPSTASH_REDIS_REST_URL=https://your-instance.upstash.io
UPSTASH_REDIS_REST_TOKEN=your_token
For Vercel KV:
KV_REST_API_URL=https://your-instance.upstash.io
KV_REST_API_TOKEN=your_token
# OR
KV_URL=rediss://default:password@host.upstash.io:6379
config.json OnlyIf you only have ~/.coaia.json:
.env file in your project directory.UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN, or Vercel KV variables)..env file will take priority over the config file.echo ".env" >> .gitignore
.env.development.env.staging.env.production.env filesFor custom Redis instances with SSL:
{
"jtaleconf": {
"host": "redis.example.com",
"port": 6380,
"password": "your_password",
"ssl": true,
"ssl_cert_reqs": "required"
}
}
The Redis client automatically manages connection pooling. For custom settings, modify the _newjtaler function in coaiamodule.py.
For issues or questions: