# Segmind Integration via LowCodeAPI

## Overview

Segmind provides fast, scalable inference APIs for AI models, focusing on optimized infrastructure for machine learning workloads. The Segmind API offers:

- **Model Inference** - Run various AI models for image and text generation
- **Account Management** - Check credit balance and account details
- **Multiple AI Models** - Access to Stable Diffusion, FLUX, and other AI models

## Base Endpoint

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

## Authentication

LowCodeAPI handles authentication automatically using API Key header authentication. You only need to:

1. **Sign up** at [Segmind](https://www.segmind.com) to get your API Key
2. **Connect your account** in the LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Segmind API key
- Apply it to each request via the x-api-key header

**Auth Type**: API Key (Header)

## API Categories

- **AI Cloud** - AI model inference and generation

## Common Endpoints

### Category: Account

#### Get User Credits

**Method**: `GET` | **LowCodeAPI Path**: `/v1/get-user-credits`

**Full URL**:
```
https://api.lowcodeapi.com/segmind/v1/get-user-credits?api_token={api_token}
```

**Description**: Get your credit balance including free credits.

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/segmind/v1/get-user-credits?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Credits](https://docs.segmind.com/api-reference/account-and-billing-apis)

---

### Category: Inference

#### Call Model Inference

**Method**: `POST` | **LowCodeAPI Path**: `/v1/modelname`

**Full URL**:
```
https://api.lowcodeapi.com/segmind/v1/{model_name}?api_token={api_token}
```

**Description**: Run inference on various AI models for image generation, text-to-image, and other AI tasks.

**Request Body**:
```json
{
  "prompt": "A beautiful landscape with mountains and a lake",
  "negative_prompt": "blurry, low quality",
  "steps": 25,
  "cfg_scale": 7,
  "width": 1024,
  "height": 1024
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `prompt` | string | Yes | Text prompt for generation |
| `negative_prompt` | string | No | Things to avoid in generation |
| `steps` | integer | No | Number of inference steps (default varies by model) |
| `cfg_scale` | number | No | How strictly to follow prompt (default: 7) |
| `width` | integer | No | Output image width (default: 1024) |
| `height` | integer | No | Output image height (default: 1024) |
| `seed` | integer | No | Random seed for reproducibility |

**Available Models**:
- `fast-flux-schnell` - Fast FLUX for quick generation
- `sdxl1.0-newreality-lightning` - SDXL with lightning
- `instantid` - Instant ID generation
- `stable-diffusion` - Standard Stable Diffusion

**Example Request**:
```bash
# Replace MODEL_NAME with actual model name
curl -X POST "https://api.lowcodeapi.com/segmind/v1/fast-flux-schnell?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene mountain landscape at sunset",
    "negative_prompt": "blurry, low quality",
    "steps": 25,
    "width": 1024,
    "height": 1024
  }'
```

**Official Documentation**: [Model Inference](https://docs.segmind.com/api-reference)

---

## Usage Examples

### Example 1: Generate Image with FLUX

Use the fast FLUX model for image generation:

```bash
# Step 1: Check credit balance
# No ID needed - returns account credits
curl -X GET "https://api.lowcodeapi.com/segmind/v1/get-user-credits?api_token=YOUR_API_TOKEN"

# Step 2: Generate image with FLUX
# No ID needed - starts generation
curl -X POST "https://api.lowcodeapi.com/segmind/v1/fast-flux-schnell?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A futuristic city with flying cars and neon lights",
    "steps": 20,
    "width": 1024,
    "height": 1024
  }'
```

### Example 2: Generate with SDXL

Use SDXL model for high-quality images:

```bash
# Generate with SDXL NewReality Lightning
# No ID needed - starts generation
curl -X POST "https://api.lowcodeapi.com/segmind/v1/sdxl1.0-newreality-lightning?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A portrait of a warrior in detailed armor",
    "negative_prompt": "ugly, deformed, blurry",
    "steps": 30,
    "cfg_scale": 7.5,
    "width": 1024,
    "height": 1024
  }'
```

### Example 3: Use Different Models

Explore various AI models:

```bash
# Use Stable Diffusion
# No ID needed - starts generation
curl -X POST "https://api.lowcodeapi.com/segmind/v1/stable-diffusion?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A magical forest with bioluminescent plants",
    "steps": 50,
    "seed": 12345
  }'

# Use InstantID
# No ID needed - starts generation
curl -X POST "https://api.lowcodeapi.com/segmind/v1/instantid?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Professional headshot in studio lighting"
  }'
```

## Complete Endpoint Reference

For a complete list of all 4 endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/segmind/definition
- **Official Segmind Documentation**: https://docs.segmind.com/api-reference

## Rate Limits & Best Practices

- **Rate Limit**: Refer to your Segmind plan for rate limits
- **Best Practices**:
  - Check credit balance before large batch operations
  - Use appropriate model for your use case (FLUX for speed, SDXL for quality)
  - Adjust steps based on desired quality vs speed trade-off
  - Use negative prompts to improve generation quality
  - Set seed for reproducible results
  - Monitor credit usage to avoid interruptions
  - Start with fewer steps to test, then increase

## Error Handling

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Segmind
  }
}
```

Common errors:
- **400**: Invalid request parameters
- **401**: Invalid API key
- **402**: Insufficient credits
- **429**: Rate limit exceeded
- **500**: Model inference failed