How do you manage API keys and secrets across environments?
Deployment and LLMOps · Intermediate 3
Short answer
Never commit secrets to code. Keep them in a secret manager or the platform's encrypted environment variables, with different keys for development, staging and production, scoped to least privilege. Inject them at runtime, rotate them regularly and after any leak, restrict who can read them, and scan repositories for accidental commits.
Deeper answer
If a key does leak, revoke it immediately: deleting the commit is not enough because history and forks keep it. Provider spending limits reduce the damage of a leaked model API key.
Infrastructure as code, such as Terraform, should reference secrets, not contain them, and its state files can hold sensitive values, so store state securely.
What a strong answer covers
- Never in code or Git
- Secret manager or encrypted environment variables
- Separate keys per environment, least privilege
- Rotate and revoke on leak
- Scan repositories and restrict access
Answer it out loud in the mock interview about 1 min
Follow-ups to expect
- What do you do in the first hour after a key leaks?
- Why separate keys per environment?
Common mistakes
- Keys in .env files committed to Git
- Sharing one production key across all developers
Learn it
Environments, secrets and Terraform
- When would you serve predictions in batch, and when online?
- How would you set up CI/CD for an LLM application?
- What is the difference between data parallelism and model parallelism?
- Why does experiment tracking matter, and what do you record?
- Your model scored well offline but performed badly after launch. What could explain it?
- Explain Kubernetes pods, deployments and services, and why you would use Kubernetes for AI apps.
- What is the KV cache, and why can it cause out-of-memory errors when serving an LLM?
- How would you load test an LLM feature and set a latency budget?
- Your model provider has an outage during peak hours. What should already be in place?
- How do you detect and handle model drift in production?
- A bank wants your AI system but says no data may leave its network. What are the options?
- Why does an LLM reply have a wait before the first word and then a different speed after it?
- What is quantisation, and what are the trade-offs?
- When would you use a semantic cache for an LLM app, and what can go wrong?
- How would you serve an LLM feature as an API for a web app?
- How would you serve a model that is too big for one GPU, and how would you scale it to more users?
- How would you add single sign-on to an enterprise AI assistant?
- How do you version prompts and models so you can roll back safely?
- What would you capture in traces for an LLM application?
- Why use Docker for an AI application?
- What does an LLM gateway do, and when do you need one?
- Why use vLLM to serve an open-weight model instead of a simple Hugging Face script?