Skip to main content
curl -X POST "https://api.strike.markets/api-key/generate" \
  -H "X-API-Key: stk_service_key_or_existing_key" \
  -H "X-Wallet-Address: 0x742d35cc6c6c7532b1140da4c8a2f6c8ecfc9b46" \
  -H "Content-Type: application/json"
{
  "success": true,
  "api_key": "stk_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
  "wallet_address": "0x742d35cc6c6c7532b1140da4c8a2f6c8ecfc9b46",
  "created_at": "2024-01-15T14:30:00Z",
  "message": "API key generated successfully. Save this key - it won't be shown again!"
}
curl -X POST "https://api.strike.markets/api-key/generate" \
  -H "X-API-Key: stk_service_key_or_existing_key" \
  -H "X-Wallet-Address: 0x742d35cc6c6c7532b1140da4c8a2f6c8ecfc9b46" \
  -H "Content-Type: application/json"
{
  "success": true,
  "api_key": "stk_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
  "wallet_address": "0x742d35cc6c6c7532b1140da4c8a2f6c8ecfc9b46",
  "created_at": "2024-01-15T14:30:00Z",
  "message": "API key generated successfully. Save this key - it won't be shown again!"
}

Description

Generate a new API key for a wallet address. Each wallet can only have one active API key at a time. If an API key already exists for the wallet, it must be revoked first before generating a new one.

Important Notes

Save your API key immediately! The API key is only shown once during generation. It cannot be retrieved later. If you lose your key, you’ll need to revoke it and generate a new one.

Authentication

This endpoint requires either:
  • A service key (used by the frontend) with the wallet address in the X-Wallet-Address header
  • An existing valid API key for the same wallet (for regeneration after revocation)

Request Headers

HeaderTypeRequiredDescription
X-API-KeystringYesService key or existing API key
X-Wallet-AddressstringConditionalRequired when using service key
Content-TypestringYesMust be application/json

Response Fields

FieldTypeDescription
successbooleanWhether the operation was successful
api_keystringThe newly generated API key (save this!)
wallet_addressstringThe wallet address associated with this key
created_atstringISO 8601 timestamp of key creation
messagestringInformational message about the operation

Error Codes

CodeDescription
API_KEY_EXISTSAn API key already exists for this wallet
INVALID_WALLETThe provided wallet address is invalid
UNAUTHORIZEDMissing or invalid authentication
INTERNAL_ERRORServer error during key generation

Usage Flow

  1. First Time Setup:
    • Connect wallet to Strike Protocol web interface
    • Navigate to API Keys section
    • Click “Generate API Key”
    • Save the key immediately
  2. Regenerating a Key:
    • First revoke the existing key using /api-key/revoke
    • Then generate a new key using this endpoint
    • Update your applications with the new key
  3. From Code:
    • Use the service key if building a frontend application
    • Use your existing API key if regenerating programmatically

Security Considerations

  • API keys are generated using cryptographically secure random functions
  • Keys are hashed before storage in the database (SHA-256)
  • The plaintext key is never stored and cannot be recovered
  • Each wallet can only have one active key at a time
  • Keys do not expire but should be rotated periodically

Rate Limiting

This endpoint is rate-limited to prevent abuse:
  • 5 requests per minute per wallet address
  • 20 requests per hour per wallet address

Example Integration

class StrikeAPIClient:
    def __init__(self, service_key: str):
        self.service_key = service_key
        self.base_url = "https://api.strike.markets"
    
    def generate_api_key(self, wallet_address: str) -> str:
        """Generate a new API key for the given wallet"""
        
        headers = {
            'X-API-Key': self.service_key,
            'X-Wallet-Address': wallet_address,
            'Content-Type': 'application/json'
        }
        
        response = requests.post(
            f"{self.base_url}/api-key/generate",
            headers=headers
        )
        
        if response.status_code == 200:
            data = response.json()
            # In production, save this key securely
            return data['api_key']
        elif response.status_code == 409:
            raise Exception("API key already exists. Revoke it first.")
        else:
            raise Exception(f"Failed to generate key: {response.json()}")

# Usage
client = StrikeAPIClient(os.environ['STRIKE_SERVICE_KEY'])
api_key = client.generate_api_key("0x742d35cc6c6c7532b1140da4c8a2f6c8ecfc9b46")
print(f"Generated API Key: {api_key}")
# Save this key securely!