How can I use litellm admin api /user/new?
- User
How can I use litellm admin api /user/new?
Assistant
How can I use litellm admin api /user/new?
Okay, let's break down how to use the /user/new endpoint in the Litellm Admin API. This endpoint is used to create new users within the Litellm Admin interface. Here's a comprehensive guide, covering authentication, request structure, response details, and examples.
1. Authentication
The Litellm Admin API requires authentication. You'll need an API key. Here's how to get one:
You'll use this API key in the Authorization header of your requests.
2. Request Structure (POST /user/new)
Method: POST
Endpoint: /user/new (relative to your Litellm Admin URL, e.g., https://admin.litellm.io/api/user/new)
Headers:
Authorization: Bearer YOUR_API_KEY (Replace YOUR_API_KEY with the key you generated)Content-Type: application/jsonBody (JSON): The request body should be a JSON object with the following fields:
{
"email": "user@example.com",
"name": "John Doe",
"role": "user" // or "admin"
}
email: (Required) The email address of the new user. Must be unique.name: (Required) The full name of the new user.role: (Required) The role assigned to the user. Valid values are:
user: Standard user with limited access.admin: Administrator with full access to all features. Use this sparingly!password: (Optional) If provided, a password will be set for the user. If not provided, a temporary password will be generated and sent to the user's email address. (Strongly recommended to provide a password for security).3. Example Requests (using curl)
Here are a couple of curl examples:
Example 1: Creating a user with a password
curl -X POST \
'https://admin.litellm.io/api/user/new' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"email": "newuser@example.com",
"name": "Jane Smith",
"role": "user",
"password": "SecurePassword123!"
}'
Example 2: Creating a user without a password (temporary password will be sent)
curl -X POST \
'https://admin.litellm.io/api/user/new' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"email": "anotheruser@example.com",
"name": "Peter Jones",
"role": "user"
}'
4. Response Details
The API will return a JSON response. Here's the expected structure:
Success (HTTP 201 Created):
{
"success": true,
"message": "User created successfully",
"user": {
"id": "6543210abcdef1234567890",
"email": "newuser@example.com",
"name": "Jane Smith",
"role": "user",
"createdAt": "2023-11-08T12:00:00.000Z",
"updatedAt": "2023-11-08T12:00:00.000Z"
}
}
success: true indicates the operation was successful.message: A descriptive message.user: An object containing the details of the newly created user.Error (HTTP 400 Bad Request, 409 Conflict, etc.):
{
"success": false,
"message": "Email address already exists"
}
success: false indicates an error occurred.message: A descriptive error message. Common errors include:
5. Important Considerations
success field in the response and handle errors appropriately. Display informative error messages to the user.Debugging Tips:
This detailed guide should get you started with using the /user/new endpoint in the Litellm Admin API. Let me know if you have any other questions.