API Key
Last updated
Last updated
The Model Hub API enables developers to interact with Sahara AI's platform for creating, deploying, and managing AI pipelines. Designed to align with the OpenAI Assistants API, it provides familiar endpoints and workflows for seamless integration. This document outlines how to authenticate, generate API keys, and use the API to develop and deploy pipelines.
Sahara supports two authentication methods:
Bearer Token: Aligns with OpenAI's token-based authentication standard.
API Key: Provides more granular control with configurable permissions.
Access the Developer Portal:
Navigate to the API Key Management under your User Profile icon dropdown section.
Generate API Key:
Click Generate New API Key.
Assign permissions:
Read: Fetch model details.
Write: Create and deploy pipelines.
Admin: Full access.
Optionally, set an expiration date.
Secure Your API Key:
Copy the key immediately; it will not be shown again.
Store it securely.
Include the generated API key or bearer token in the header of your HTTP requests:
Common authentication errors:
401 Unauthorized: Invalid or missing token.
403 Forbidden: Insufficient permissions.
429 Too Many Requests: Exceeded rate limits.
Endpoint: Create a Pipeline
URL: /v1/pipelines/create
Method: POST
Description: Creates a new AI pipeline.
URL: /v1/pipelines/{pipeline_id}/test
Method: POST
Description: Allows developers to test their pipeline before deployment.
Endpoint: Deploy Pipeline
URL: /v1/pipelines/{pipeline_id}/deploy
Method: POST
Description: Deploys the pipeline to Sahara’s compute network.
Endpoint: Monitor Usage
URL: /v1/pipelines/{pipeline_id}/metrics
Method: GET
Description: Retrieves metrics such as token usage and API call statistics.
Step 1: Authenticate
Use your API key or bearer token in the header of all requests.
Step 2: Create a Pipeline
Send a POST request to /v1/pipelines/create with the required parameters. Ensure all fields are valid.
Step 3: Test the Pipeline
Test the functionality of your pipeline using /v1/pipelines/{pipeline_id}/test.
Step 4: Deploy the Pipeline
Deploy the tested pipeline via /v1/pipelines/{pipeline_id}/deploy and receive the unique inference endpoint.
Step 5: Monitor Metrics
Track usage metrics for optimization and scaling using /v1/pipelines/{pipeline_id}/metrics.
Error Codes
400 Bad Request: Check request formatting.
404 Not Found: Verify pipeline or model IDs.
500 Internal Server Error: Retry or contact support.
Best Practices
Secure Keys:
Use environment variables to store API keys securely.
Monitor Usage:
Regularly review metrics to optimize performance.
Retry Logic:
Implement retry logic for transient errors (e.g., 500 Internal Server Error).