Secure Your API Keys
Learn how to protect your ApiSmart API Keys, avoid accidental exposure, and respond quickly if a key is compromised.
Your API Key is a sensitive credential used to authenticate requests to the ApiSmart API.
Anyone with access to a valid key may be able to make API requests using the permissions available to your account. Protect your API Keys carefully and remove or disable any key that may have been exposed.
🔐 Keep API Keys Private
Treat every API Key like a password.
Do not:
Share API Keys publicly
Commit API Keys to public Git repositories
Paste API Keys into public code samples
Include full API Keys in screenshots
Store API Keys in publicly accessible files
Expose API Keys in browser-side or other untrusted client-side code
Include full API Keys in logs or error messages
Only provide an API Key to systems and applications that require it.
📦 Store Keys Outside Your Source Code
Avoid hard-coding API Keys directly in your application.
Instead, use environment variables or a secure secrets management system.
For example:
Your application can then read the value from the environment instead of storing the credential in the source code.
Python
JavaScript
Make sure files containing secrets, such as .env, are excluded from version control.
🧩 Use Separate Keys for Different Environments
When possible, use separate API Keys for different applications or environments.
For example:
Development
Testing
Staging
Production
This makes it easier to identify usage and disable a specific credential without affecting every application connected to your account.
Use descriptive key names so you can quickly understand where each key is being used.
🖥️ Keep API Keys on Trusted Servers
For web applications, API Keys should normally remain on your backend or another trusted server environment.
Avoid embedding a secret API Key directly in:
Browser JavaScript
Public frontend source code
Mobile application bundles
Public configuration files
If users can inspect the application and retrieve the key, the credential should be considered exposed.
📝 Avoid Logging Full API Keys
Application logs can be accessed by developers, monitoring tools, support systems, or other services.
Do not record complete API Keys in logs.
If you need to identify which key was used, log only a safe identifier or limited prefix rather than the complete credential.
The ApiSmart Console can also help you identify and manage existing API Keys without exposing the full credential unnecessarily.
🔄 Review Your API Keys Regularly
Periodically review the API Keys in your account.
Check whether:
Each key still belongs to an active application
Key names clearly identify their purpose
Old development or test keys are still required
Unexpected or unused keys should be disabled or deleted
Removing unused credentials reduces unnecessary exposure.
🚨 If an API Key Is Exposed
If you believe an API Key has been leaked or accessed by someone who should not have it, stop using that key as soon as possible.
Recommended steps:
Disable the exposed API Key
Create a replacement API Key
Update your application to use the new key
Verify that the application works with the replacement key
Delete the exposed key when it is no longer required
Review recent API usage for unexpected activity
Do not continue using a credential that may have been compromised.
⚠️ Authentication Errors
If a key has been disabled, deleted, or is otherwise invalid, API requests may return:
401 invalid_api_key
Verify that the application is using an active API Key and that the authentication header is formatted correctly:
A 403 model_not_allowed response is different from an authentication failure. It means the selected model is not currently available to the API Key or account.
For more information about API errors, see HTTP Status Codes and API Errors. For model access issues, see Models and Model IDs.
✅ API Key Security Checklist
Before deploying an application, verify that:
Your API Key is not hard-coded into public source code
Secret files are excluded from version control
Production credentials are stored in a secure environment
Development and production use separate API Keys where appropriate
Full API Keys are not written to logs
Public client-side applications cannot access the credential
Unused API Keys are disabled or deleted
Exposed keys are replaced immediately
➡️ Next Steps
Continue with:
Create and Manage API Keys — Create, edit, disable, and delete API Keys
Quick Start — Make your first API request
API Basics — Learn common API authentication and request conventions
最後更新於
這有幫助嗎?