Authentication overview
TensorFeed provides methods for authenticating client applications and users when interacting with its API and platform services. Proper authentication ensures that only authorized entities can deploy models, execute inference requests, manage features, and access monitoring data. The platform supports two primary authentication mechanisms: API keys for direct programmatic access and OAuth 2.0 for delegated authorization, often used in integrations or when user consent is required. All communications with the TensorFeed API are secured using Transport Layer Security (TLS) 1.2 or higher, encrypting data in transit to protect sensitive information and maintain data integrity, as detailed in the TensorFeed security documentation.
Understanding the appropriate authentication method for specific use cases is crucial for both security and operational efficiency. API keys offer a straightforward approach for server-to-server communication or script-based automation, while OAuth 2.0 provides a more granular and secure method for third-party applications or scenarios requiring user permission. TensorFeed's SDKs for Python, Go, and Java are designed to integrate seamlessly with these authentication methods, simplifying the process of securing API calls for developers.
Supported authentication methods
TensorFeed supports two main authentication methods to accommodate various integration patterns and security requirements:
- API Keys: A unique, secret token used to authenticate a project or application directly. API keys are typically long, randomly generated strings that grant access to specific resources or operations within your TensorFeed account. They are suitable for server-side applications, scripts, or environments where direct credential management is feasible and secure.
- OAuth 2.0: An authorization framework that enables third-party applications to obtain limited access to an HTTP service, either on behalf of a resource owner or by orchestrating an explicit approval interaction between the resource owner and the HTTP service. OAuth 2.0 uses access tokens instead of direct credentials, enhancing security by limiting the scope and duration of access. It is often preferred for user-facing applications or integrations that require delegated access without exposing user credentials directly. The OAuth 2.0 specification outlines various grant types to suit different application flows.
Authentication methods comparison
The following table outlines the key characteristics and recommended use cases for each authentication method:
| Method | When to Use | Security Level | Complexity |
|---|---|---|---|
| API Key | Server-to-server communication, scripts, backend services. | Medium (depends on key management) | Low |
| OAuth 2.0 | Third-party integrations, user-facing applications, delegated access. | High (token-based, scope-limited) | Medium to High (depending on grant type) |
Getting your credentials
To authenticate with TensorFeed, you must first obtain the necessary credentials from your TensorFeed account dashboard. The process varies slightly depending on whether you require an API key or OAuth 2.0 credentials.
Obtaining an API Key
- Log in to your TensorFeed account.
- Navigate to the 'Settings' or 'API Keys' section in your dashboard.
- Click 'Generate New API Key' or a similar option.
- Assign a descriptive name to your API key for easier identification (e.g., 'Production Inference Service Key').
- (Optional) Configure scope or permissions if your plan allows for granular access control.
- Copy the generated API key immediately. For security reasons, API keys are typically shown only once upon creation and cannot be retrieved later. If lost, you will need to generate a new one.
- Store your API key securely, preferably in environment variables or a secrets management service, not directly in your code.
Obtaining OAuth 2.0 Credentials
For OAuth 2.0, you will need a Client ID and Client Secret, and you may also need to configure redirect URIs.
- Log in to your TensorFeed account.
- Go to the 'Applications' or 'OAuth Clients' section within your dashboard.
- Register a new application, providing details such as the application name and a valid redirect URI (the URL where users will be sent after authorization).
- TensorFeed will issue a Client ID and Client Secret for your application.
- Copy both the Client ID and Client Secret. The Client Secret, like an API key, is often displayed only once.
- Configure the necessary OAuth scopes that your application requires (e.g.,
model:read,inference:execute). - Implement the OAuth 2.0 flow in your application, typically starting with directing users to TensorFeed's authorization endpoint, as described in the TensorFeed OAuth documentation.
Authenticated request example
This example demonstrates how to make an authenticated API request to the TensorFeed inference endpoint using an API key in Python. The example assumes you have an API key stored as an environment variable.
import os
import requests
import json
# Retrieve API key from environment variables
TENSORFEED_API_KEY = os.environ.get("TENSORFEED_API_KEY")
if not TENSORFEED_API_KEY:
raise ValueError("TENSORFEED_API_KEY environment variable not set.")
# Define the API endpoint for inference
INFERENCE_ENDPOINT = "https://api.tensorfeed.com/v1/models/{model_id}/predict"
MODEL_ID = "your_model_id_here" # Replace with your deployed model ID
# Prepare the headers with the API key
headers = {
"Authorization": f"Bearer {TENSORFEED_API_KEY}",
"Content-Type": "application/json"
}
# Prepare the payload for the inference request
# This structure depends on your model's input expectations
payload = {
"instances": [
[1.0, 2.0, 3.0, 4.0], # Example input data
[5.0, 6.0, 7.0, 8.0]
]
}
try:
# Make the POST request to the inference endpoint
response = requests.post(
INFERENCE_ENDPOINT.format(model_id=MODEL_ID),
headers=headers,
data=json.dumps(payload)
)
# Check if the request was successful
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
# Parse and print the JSON response
inference_results = response.json()
print("Inference successful:")
print(json.dumps(inference_results, indent=2))
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err} - {response.text}")
except requests.exceptions.ConnectionError as conn_err:
print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
print(f"An unexpected error occurred: {req_err}")
This Python example demonstrates how to set the Authorization header with a Bearer token, which is the standard practice for API key authentication on TensorFeed. For OAuth 2.0, the process would involve obtaining an access token first, then using that token in the Authorization: Bearer header.
Security best practices
Implementing strong security practices when managing and using TensorFeed credentials is essential to protect your data and ML models from unauthorized access. The following guidelines apply to both API keys and OAuth 2.0 credentials:
- Protect your credentials: Never hardcode API keys or client secrets directly into your application code. Use environment variables, secret management services (e.g., AWS Secrets Manager, Google Secret Manager), or secure configuration files. This prevents credentials from being exposed in version control systems or publicly accessible code repositories.
- Rotate credentials regularly: Periodically rotate your API keys and client secrets. This practice limits the window of exposure should a credential be compromised. TensorFeed provides mechanisms in the dashboard to regenerate keys or secrets.
- Implement Least Privilege: Grant credentials only the minimum necessary permissions required for their intended function. For instance, an API key used for inference should not have permissions to delete models. TensorFeed supports Role-Based Access Control (RBAC) to enforce granular permissions, as described in their access control documentation.
- Monitor API usage: Regularly review API access logs and monitoring data provided by TensorFeed. Unusual patterns, such as an increase in failed authentication attempts or requests from unexpected geographical locations, could indicate a compromise.
- Use HTTPS/TLS exclusively: All communication with the TensorFeed API must occur over HTTPS (TLS). This ensures that credentials and data exchanged are encrypted in transit, preventing eavesdropping and man-in-the-middle attacks. This is a standard requirement for secure web communication, as highlighted by organizations like the World Wide Web Consortium (W3C).
- Secure your development environment: Ensure that your local development machines and deployment pipelines are secure. Avoid storing credentials on insecure file systems or sharing them through unencrypted channels.
- Client-side considerations for OAuth 2.0: If using OAuth 2.0 in client-side applications (e.g., single-page applications), use the Authorization Code Flow with PKCE (Proof Key for Code Exchange) to mitigate authorization code interception attacks. Never store client secrets in client-side code.
- Implement Rate Limiting and Circuit Breakers: While not strictly an authentication practice, implementing these patterns in your client applications can prevent abuse of your authenticated API access and protect your application from cascading failures.