# API Reference

## Authentication

#### Create an API key

The Segmind Serverless API uses API keys for authentication. To create one, login to your account and head to the [API Keys page](https://cloud.segmind.com/console/api-keys) on the dashboard.

#### Use the API

You can authenticate by including your Segmind API key in the Request Header and pass it as `x-api-key` section of the request.

Example cURL request:

```
curl --location 'https://api.segmind.com/v1/instantid' \
--header 'x-api-key: YOUR-API-KEY' \
--header 'Content-Type: application/json' \
--data '{
    }'
```

Example Python request:

```python
import requests

api_key = "YOUR-API-KEY"
url = "https://api.segmind.com/v1/face-to-sticker"

# Request payload
data = {
}

response = requests.post(url, json=data, headers={'x-api-key': api_key})
print(response)
```

## APIs <a href="#create-an-account" id="create-an-account"></a>

To integrate an API, visit the model's page and [click on the "API"](https://www.segmind.com/models/sdxl1.0-newreality-lightning/api) tab. You can see the list of parameters and example code to get started with the API.

## Endpoints

**Base URL**

`POST https://api.segmind.com/...`

**Version 1 (v1)**

Some endpoints that typically complete their requests within 60 seconds are on version 1. For example: `https://api.segmind.com/v1/sdxl1.0-newreality-lightning`

**Version 2 (v2)**

We created v2 to serve APIs that typically take longer than 60 seconds to process.

## API error codes <a href="#create-an-account" id="create-an-account"></a>

Below are the HTTP status codes returned by the Segmind API:

```
| Code | Status | Description | Billed? |
|---|---|---|---|
| **200** | Output Generated | Request completed successfully and output was produced. | Yes |
| **401** | Unauthorized | User authentication failed. Check your API key. | No |
| **404** | Not Found | The requested model endpoint or URL does not exist. | No |
| **405** | Method Not Allowed | The requested HTTP method is not supported for this endpoint. | No |
| **406** | Not Acceptable | Not enough credits in your account to process the request. | No |
| **422** | Validation Error | Invalid or missing parameters in the request body. | No |
| **429** | Too Many Requests | Rate limit exceeded. Retry after a short delay. | No |
| **500** | Server Error | An internal server error occurred during processing. | No |
```

{% hint style="info" %}
**Billing note:** You are only charged for requests that return HTTP 200 (successful output). All error responses (4xx and 5xx) result in a full credit rollback — no charges are applied. See [Pricing and Billing](https://docs.segmind.com/readme/pricing-and-billing#billing-on-api-errors) for more details on the credit reservation system.
{% endhint %}

## Postman Collection <a href="#create-an-account" id="create-an-account"></a>

Use this Postman collection to get started faster.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.segmind.com/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
