# Access and Authentication

This section provides a detailed guide on how to access Fotor OpenAPI and authenticate your requests to ensure secure usage of our API services.  

## API Endpoint  
```
https://api-b.fotor.com  
```  

## Authentication  
Fotor OpenAPI uses Bearer Token authentication. You must include your API key in the `Authorization` header of every request.  

```
Authorization: Bearer <your_api_key>
```  

Here, `<your_api_key>` is the API key you obtained from the Fotor Developer Platform.  

### How to Obtain an API Key  
1. Visit the [[Fotor Developer Platform]](https://developers.fotor.com/)(#) (register for an account if you haven’t already).  
2. Sign up as a developer.  
3. Navigate to the Settings and find the API Key Management page to create your API key.  
4. Keep your API key secure and avoid sharing it.  

## Request Headers  
In addition to the `Authorization` header, you must specify the `Content-Type` header as `application/json`, indicating that the request body is in JSON format.  

```
Content-Type: application/json
```  

## Example Request (Using cURL)  
Below is an example of sending a request using cURL, demonstrating how to include the `Authorization` and `Content-Type` headers:  

```bash
curl --location 'https://api-b.fotor.com/v1/aiart/img2img' \
--header 'Authorization: Bearer <your_api_key>' \
--header 'Content-Type: application/json' \
--data '{
    "content": "a boy",
    "userImageUrl": "https://u-static.fotor.com/uid_b195b7a44afc47ffb13dcfa82ad3935e/image_to_image/app-fotor-web/d6e711de-ddad-4019-892f-837a8a421fc5.jpg",
    "templateId": "04c2781d-cb64-499d-9542-04788e834665",
    "negativePrompt": "girl",
    "strength": 0.45
}'
```  

Replace `<your_api_key>` with your actual API key.  

## Error Handling  
If your request is missing or contains an invalid `Authorization` token, the API will return a `401 Unauthorized` error. You should verify your API key and ensure it is correctly included in the request header.  

Other common HTTP status codes include:  
- **400 Bad Request**: The request parameters are incomplete or incorrectly formatted.  
- **429 Too Many Requests**: Excessive request rate.  
- **500 Internal Server Error**: A server-side error occurred.  

The API also returns a JSON response body with `code` and `msg` fields to provide more detailed error information:  
- **000**: Success  
- **999**: Unknown error  

## Summary  
To successfully access Fotor OpenAPI, you need to:  
1. Use the correct API endpoint.  
2. Include a valid API key in the `Authorization` header.  
3. Set the `Content-Type` header to `application/json`.  

By following these steps, you can securely and effectively utilize the features of Fotor OpenAPI.  

If you encounter any issues during access or authentication, please contact our technical support team promptly.  

