⚡ Account Provisioning & Credential Management
Before logging LLM requests or publishing versioned prompt templates, you must set up your PromptLayer organization workspace, generate secure API credentials (`pl_live_...`), and configure your backend environment variables correctly.
1. Real-Time Example: Enterprise Workspace & Team Provisioning
Configuring a multi-tenant PromptLayer workspace for Nikita Infotech, establishing organization billing limits, and inviting engineering team members.
Workspace Provisioning Checklist
WORKSPACE CONFIGURATION SUMMARY:
- Organization Name: Nikita Infotech Enterprise
- Default Workspace: Production-Core
- Team Roles Assigned:
* Admin / Owner: devlead@nikita-infotech.com
* Prompt Engineer: ai-author@nikita-infotech.com
* Viewer / Auditor: security@nikita-infotech.com
- Billing Alert Threshold: $500.00 / month token budget
Provisioning Status: Workspace active. Multi-tenant access controls and audit logging enabled.
2. Real-Time Example: Secure API Key Generation & .env Setup
Generating live and test API keys in the PromptLayer dashboard and securely injecting them into backend environment files.
Environment Variables (.env)
# PromptLayer & LLM Provider Credentials
PROMPT_LAYER_API_KEY=pl_live_9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d
OPENAI_API_KEY=sk-proj-abc123xyz789...
ANTHROPIC_API_KEY=sk-ant-api03-fedcba987...
Security Status: API keys stored securely in server environment variables. Public repository exposure prevented via `.gitignore`.
3. Real-Time Example: Authenticated SDK Initialization in Python
Initializing the PromptLayer OpenAI wrapper in Python using environment-injected credentials to automatically log all API calls.
Python (initialize_sdk.py)
import os
import promptlayer
from openai import OpenAI
# Automatically loads PROMPT_LAYER_API_KEY and OPENAI_API_KEY from environment
client = promptlayer.openai.OpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
promptlayer_api_key=os.getenv("PROMPT_LAYER_API_KEY")
)
def test_connection():
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Confirm PromptLayer connection status."}],
pl_tags=["setup-verification", "production-init"]
]
print("[*] Response:", response.choices[0].message.content)
if __name__ == "__main__":
test_connection()
Execution Output:
[*] Response: PromptLayer connection established successfully. Request logged to workspace Nikita Infotech.
4. Real-Time Example: Node.js Express Server Credential Binding
Configuring PromptLayer within a Node.js Express backend proxy to log authenticated API transactions securely.
JavaScript (server_setup.js)
import express from 'express';
import PromptLayer from 'promptlayer';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
app.use(express.json());
// Initialize PromptLayer tracking client
PromptLayer.api_key = process.env.PROMPT_LAYER_API_KEY;
app.post('/api/ai-chat', async (req, res) => {
try {
const { prompt } = req.body;
// Tracked OpenAI completion call via PromptLayer
const openaiResponse = await PromptLayer.track.openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: prompt }],
return_pl_id: true // Returns PromptLayer request log ID
});
res.json({
success: true,
reply: openaiResponse.choices[0].message.content,
promptlayer_request_id: openaiResponse.request_id
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000, () => console.log('Secure server running on port 3000'));
Execution Output:
Secure server running on port 3000
[PromptLayer Node.js SDK] Successfully authenticated and tracking request ID: pl_req_998877.
5. Real-Time Example: API Key Rotation & Security Audit Workflow
Establishing an automated security protocol for rotating compromised PromptLayer API keys without causing downtime.
Python (key_rotation_audit.py)
import promptlayer
import os
def audit_api_credentials():
promptlayer.api_key = os.getenv("PROMPT_LAYER_API_KEY")
try:
# Perform lightweight ping to verify key validity
workspace_info = promptlayer.get_workspace_metadata()
print(f"[AUDIT SUCCESS] Connected to Workspace: {workspace_info.get('name', 'Nikita Infotech')}")
print("[AUDIT SUCCESS] API Key status: ACTIVE & SECURE")
except Exception as e:
print(f"[SECURITY ALERT] Authentication failed: {str(e)}. Initiate immediate key rotation!")
if __name__ == "__main__":
audit_api_credentials()
Execution Output:
[AUDIT SUCCESS] Connected to Workspace: Nikita Infotech
[AUDIT SUCCESS] API Key status: ACTIVE & SECURE