EN ▾
Create key

Securing Your API Key: Prevention and Leak Response

A leaked API key can quickly turn a small project into a financial disaster. This guide walks you through preventing unauthorized access and handling the aftermath if your key is exposed.

Secure digital vault with glowing blue light representing API key security

Why Key Security Matters

API keys are the primary way to authenticate requests to our service. When you generate a key, it grants access to your account and allows usage of the uncensored text model. If this key falls into the wrong hands, anyone can make requests on your behalf. This is not just a theoretical risk; developers often discover leaked keys after receiving unexpected charges or account suspensions.

The most common cause of leaks is committing keys to version control systems like GitHub. Even if you delete the file later, the history remains. Another frequent source is sharing keys in public forums or chat groups without realizing it. Once a key is public, it can be scraped by bots within minutes.

Our API charges based on token usage, so a leaked key can drain your prepaid credit quickly. Since there is no subscription fee, your account might not be suspended immediately, but your balance will drop. Understanding how keys work helps you take proactive steps to secure them before an incident occurs.

Securing your key is essential for maintaining control over your spending. By treating your key like a password, you reduce the risk of unauthorized access. This guide provides actionable steps to keep your key safe and respond effectively if it is compromised.

Preventing Leaks with Environment Variables

The best way to prevent leaks is to avoid hardcoding keys in your source code. Instead, use environment variables to store sensitive information. This method keeps your key out of your code repository, making it harder for others to find. Most development environments support loading variables from a .env file or system settings.

When you set up your project, create a file named .env to store your key. Add this file to your .gitignore file to ensure it is not tracked by version control. This simple step prevents accidental commits of sensitive data. You can then access the key in your code using standard environment variable functions.

For team projects, consider using a secret management tool to share keys securely. This ensures that all team members can access the key without exposing it in the codebase. Regularly review your repository history to check for any accidental commits of keys. If you find one, rotate the key immediately.

Using environment variables is a standard practice in modern development. It adds a layer of security without complicating your workflow. By adopting this habit, you protect your account from common leaks and maintain control over your API usage.

Detecting Unauthorized Usage

Monitoring your API usage is important for detecting unauthorized access early. Our API provides usage data that you can track to identify unusual patterns. Look for sudden spikes in token consumption or requests from unexpected sources. If you see activity that does not match your project's normal behavior, investigate immediately.

Rate limits can help mitigate damage from a leaked key. Our service allows up to 300 requests per minute per key. If a key is abused, it might hit this limit, which can slow down the attack but not stop it entirely. Monitoring your rate limit usage can alert you to potential abuse.

Errors like 401 or 402 can indicate issues with your key or credit balance. If you receive unexpected errors, check your account status and usage history. A 402 error means you have no credit, while a 401 error indicates an invalid key. These errors can help you diagnose problems with your API access.

Regularly reviewing your usage data helps you stay informed about your account's health. It allows you to spot anomalies before they become major issues. By keeping an eye on your usage, you can respond quickly to any signs of unauthorized access.

Immediate Steps After a Leak

If you discover that your API key has been leaked, the first step is to rotate it. Generate a new key in your account dashboard and replace the old one in your environment variables. This action invalidates the leaked key, preventing further unauthorized use. Make sure to update all places where the old key was used.

Next, check your usage history to assess the damage. Look for any unusual activity that occurred before you rotated the key. This will help you understand the extent of the leak and whether any credit was used. Our API charges by real token usage, so you can see exactly how much was consumed.

If you have prepaid credit, it will be charged for the unauthorized usage. Errors and refusals are free, so you only pay for actual tokens processed. Review your balance to see how much credit remains. If the balance is low, you may need to top up to continue using the service.

Finally, update your documentation and inform your team about the new key. Ensure that everyone is using the correct key in their development environments. This helps prevent confusion and ensures smooth operation of your project. Quick action minimizes the impact of a leak.

When Our API Is Not the Right Choice

While our API is excellent for text generation, it may not be the right choice for all projects. If you need image, audio, or video generation, our service does not offer these capabilities. It focuses solely on text input and output, so projects requiring multimedia content should look elsewhere.

Similarly, if you need embeddings for semantic search, our API does not provide this feature. It is designed for chat completions and responses, not for creating vector representations of text. Projects relying on embeddings should consider services that specialize in this area.

OCR and fine-tuning are also not supported by our API. If you need to extract text from images or train custom models, our uncensored text model may not meet your needs. In these cases, you might need to combine our API with other tools or choose a different provider.

Understanding the limitations of our API helps you decide if it fits your project. It is a powerful tool for text generation, but it has specific boundaries. By knowing what it does and does not offer, you can make informed decisions about your tech stack.

Addressing Community Concerns

Developers often discuss key security and pricing on Reddit, particularly in threads on r/openrouter and r/ExperiencedDevs. A common concern is how companies handle LLM pricing and whether leaked keys can lead to unexpected bills. Many developers share their experiences with key leaks and how they managed the aftermath.

Another topic is the comparison between Chinese LLMs and US frontier models. Users discuss the quality and pricing of models like DeepSeek and Qwen, noting that they can rival frontier models in certain tasks. However, the focus here is on securing your key regardless of the model you use.

Some threads mention leaked keys causing significant issues, such as suspended accounts or large bills. While our API has a prepaid credit system, a leaked key can still drain your balance. The key takeaway is to monitor usage and rotate keys promptly.

By addressing these community concerns, we provide a comprehensive view of the risks involved. Developers can learn from others' experiences and apply best practices to their own projects. This helps create a more secure ecosystem for everyone.

Best Practices for Ongoing Security

To maintain long-term security, adopt a routine of regular key rotation. Change your keys every few months or after any suspected breach. This reduces the window of opportunity for attackers who might have obtained an old key. It also helps you stay ahead of potential vulnerabilities.

Use strong, unique keys for different environments, such as development and production. This isolates risks and prevents a leak in one environment from affecting others. Our API allows you to generate multiple keys, so take advantage of this feature.

Keep your environment variables secure and accessible only to authorized personnel. Avoid sharing keys via email or chat unless necessary. If you must share them, use a secure method and change them afterward. Consistency in your security practices builds a strong defense against leaks.

Finally, stay informed about updates to our API and security best practices. Regularly review our documentation for any new features or changes. By staying proactive, you can protect your account and ensure smooth operation of your projects. Security is an ongoing process, not a one-time fix.

Frequently asked questions

How do I rotate my API key?

You can rotate your key by generating a new one in your account dashboard and replacing the old key in your environment variables. This invalidates the old key immediately.

What happens if my key is leaked?

If your key is leaked, unauthorized users can make requests on your behalf. You should rotate the key immediately and check your usage history to assess any damage.

Can I use environment variables to secure my key?

Yes, using environment variables is a best practice. It keeps your key out of your code repository and reduces the risk of accidental commits.

Does our API support image generation?

No, our API is designed for text input and output only. It does not support image, audio, or video generation.