# Getting Started

Base URL, first API call, response format, error handling, and pagination

## Base URL

All API requests are made to:

```
https://app.steelengine.com
```

## Quick Start

### Get your API key

Go to the SteelEngine platform and navigate to **Settings**, then go to **SteelEngine Keys** and click **Create**. See [Authentication](/api-reference/authentication) for details on key types.

### Find your workflow ID

Open a workflow in the SteelEngine editor. The workflow ID is in the URL:

```
https://app.steelengine.com/workspace/{workspaceId}/w/{workflowId}
```

You can also use the [List Workflows](/api-reference/workflows/listWorkflows) endpoint to get all workflow IDs in a workspace.

### Deploy your workflow

A workflow must be deployed before it can be executed via the API. Click the **Deploy** button in the editor toolbar, or use the dashboard to manage deployments.

### Make your first request

**curl**

```bash
curl -X POST https://steelengine.com/api/workflows/{workflowId}/execute \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{"inputs": {}}'
```

**TypeScript**

```typescript
const response = await fetch(
  `https://steelengine.com/api/workflows/${workflowId}/execute`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.STEELENGINE_API_KEY!,
    },
    body: JSON.stringify({ inputs: {} }),
  }
)

const data = await response.json()
console.log(data.output)
```

**Python**

```python
import requests
import os

response = requests.post(
    f"https://steelengine.com/api/workflows/{workflow_id}/execute",
    headers={
        "Content-Type": "application/json",
        "X-API-Key": os.environ["STEELENGINE_API_KEY"],
    },
    json={"inputs": {}},
)

data = response.json()
print(data["output"])
```

## Sync vs Async Execution

By default, workflow executions are **synchronous** — the API blocks until the workflow completes and returns the result directly.

For long-running workflows, use **asynchronous execution** by passing `async: true`:

```bash
curl -X POST https://steelengine.com/api/workflows/{workflowId}/execute \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{"inputs": {}, "async": true}'
```

This returns immediately with a `taskId`:

```json
{
  "success": true,
  "taskId": "job_abc123",
  "status": "queued"
}
```

Poll the [Get Job Status](/api-reference/workflows/getJobStatus) endpoint until the status is `completed` or `failed`:

```bash
curl https://steelengine.com/api/jobs/{taskId} \
  -H "X-API-Key: YOUR_API_KEY"
```

Job status transitions follow: `queued` → `processing` → `completed` or `failed`. The `output` field is only present when status is `completed`.

## Response Format

Successful responses include an `output` object with your workflow results and a `limits` object with your current rate limit and usage status:

```json
{
  "success": true,
  "output": {
    "result": "Hello, world!"
  },
  "limits": {
    "workflowExecutionRateLimit": {
      "sync": {
        "requestsPerMinute": 60,
        "maxBurst": 10,
        "remaining": 59,
        "resetAt": "2025-01-01T00:01:00Z"
      },
      "async": {
        "requestsPerMinute": 30,
        "maxBurst": 5,
        "remaining": 30,
        "resetAt": "2025-01-01T00:01:00Z"
      }
    },
    "usage": {
      "currentPeriodCost": 1.25,
      "limit": 50.00,
      "plan": "pro",
      "isExceeded": false
    }
  }
}
```

## Error Handling

The API uses standard HTTP status codes. Error responses include a human-readable `error` message:

```json
{
  "error": "Workflow not found"
}
```

| Status | Meaning                    | What to do                                          |
| ------ | -------------------------- | --------------------------------------------------- |
| `400`  | Invalid request parameters | Check the `details` array for specific field errors |
| `401`  | Missing or invalid API key | Verify your `X-API-Key` header                      |
| `403`  | Access denied              | Check you have permission for this resource         |
| `404`  | Resource not found         | Verify the ID exists and belongs to your workspace  |
| `429`  | Rate limit exceeded        | Wait for the duration in the `Retry-After` header   |

Use the [Get Usage Limits](/api-reference/usage/getUsageLimits) endpoint to check your current rate limit status and billing usage at any time.

## Rate Limits

Rate limits depend on your subscription plan and apply separately to synchronous and asynchronous executions. Every execution response includes a `limits` object showing your current rate limit status.

When rate limited, the API returns a `429` response with a `Retry-After` header indicating how many seconds to wait before retrying.

## Pagination

List endpoints (workflows, logs, audit logs) use **cursor-based pagination**:

```bash
# First page
curl "https://steelengine.com/api/v1/logs?limit=20" \
  -H "X-API-Key: YOUR_API_KEY"

# Next page — use the nextCursor from the previous response
curl "https://steelengine.com/api/v1/logs?limit=20&cursor=abc123" \
  -H "X-API-Key: YOUR_API_KEY"
```

The response includes a `nextCursor` field. When `nextCursor` is absent or `null`, you have reached the last page.
