> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x402layer.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Enterprise API Reference

> REST API for enterprise partners to integrate Singularity Layer into their platform

# Enterprise API Reference

The Enterprise API lets you integrate Singularity Layer directly into your platform. Your backend authenticates with an API key and can list endpoints, query revenue, and track transactions programmatically.

<CardGroup cols={2}>
  <Card title="Get Partner Config" icon="gear" href="/api-reference/enterprise-config">
    Retrieve your pricing overrides and revenue split percentages.
  </Card>

  <Card title="List Endpoints" icon="server" href="/api-reference/enterprise-endpoints">
    View all endpoints deployed through your enterprise program.
  </Card>

  <Card title="Revenue Stats" icon="chart-line" href="/api-reference/enterprise-stats">
    Aggregated revenue summary with three-way split totals.
  </Card>

  <Card title="Transaction Ledger" icon="receipt" href="/api-reference/enterprise-transactions">
    Full payment history with per-transaction split details.
  </Card>
</CardGroup>

## Authentication

All Enterprise API requests require an API key passed via the `X-Enterprise-Key` header:

```bash theme={null}
curl https://studio.x402layer.cc/api/v1/enterprise \
  -H "X-Enterprise-Key: sgl_ent_your_api_key_here"
```

### Getting an API Key

1. Go to your [Enterprise Dashboard](https://studio.x402layer.cc/enterprise/dashboard)
2. Navigate to **API Keys**
3. Click **Create Key**
4. Copy the key — it is only shown once

Keys use the `sgl_ent_` prefix. You can create up to 10 active keys per partner. Keys can be set to expire after 30, 90, or 365 days, or never.

## Base URL

```
https://studio.x402layer.cc/api/v1/enterprise
```

***

## Code Examples

Quick integration examples in TypeScript and Python.

### TypeScript — List Endpoints

```typescript theme={null}
const API_KEY = process.env.ENTERPRISE_API_KEY;
const BASE = "https://studio.x402layer.cc/api/v1/enterprise";

const res = await fetch(`${BASE}/endpoints?page=1&limit=50`, {
  headers: { "X-Enterprise-Key": API_KEY },
});
const { endpoints, pagination } = await res.json();

for (const ep of endpoints) {
  console.log(ep.slug, ep.owner_credits, ep.is_active ? "active" : "paused");
}
```

### Python — Query Revenue Stats

```python theme={null}
import os, requests

API_KEY = os.environ["ENTERPRISE_API_KEY"]
BASE = "https://studio.x402layer.cc/api/v1/enterprise"

stats = requests.get(
    f"{BASE}/stats",
    headers={"X-Enterprise-Key": API_KEY},
).json()

print(f"Total revenue: ${stats['total_revenue']:.2f}")
print(f"Your earnings: ${stats['enterprise_earned']:.2f}")
print(f"Pending payout: ${stats['pending_payout']:.2f}")
```

### TypeScript — Verify Webhook Signature

```typescript theme={null}
import { createHmac } from "crypto";

function verifyWebhook(rawBody: string, headers: Record<string, string>, secret: string): boolean {
  const signature = headers["x-x402-signature"];
  const timestamp = headers["x-x402-timestamp"];
  if (!signature || !timestamp) return false;

  const expected = createHmac("sha256", secret)
    .update(timestamp + "." + rawBody)
    .digest("hex");

  return signature === expected;
}

// In your webhook handler:
app.post("/webhooks/singularity", (req, res) => {
  if (!verifyWebhook(req.rawBody, req.headers, process.env.WEBHOOK_SECRET)) {
    return res.status(401).send("Invalid signature");
  }
  const event = JSON.parse(req.rawBody);
  console.log(event.event, event.source_slug, event.amount);
  res.status(200).send("ok");
});
```

***

## Worker API (Endpoint Creation)

When agents on your platform deploy endpoints, they call the Singularity worker API. You can authenticate the request with your enterprise API key instead of the public `?partner=slug` parameter:

```bash theme={null}
curl -X POST https://api.x402layer.cc/agent/endpoints \
  -H "X-Enterprise-Key: sgl_ent_your_api_key_here" \
  -H "X-Payment: <x402-payment-payload>" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My Agent API",
    "url": "https://my-agent.com/api",
    "description": "Agent-powered data analysis",
    "chain": "base",
    "pricing_model": "credit",
    "category": "AI Tools"
  }'
```

The `X-Enterprise-Key` header replaces `?partner=your-slug` and provides authenticated partner identification. The x402 payment flow is unchanged — agents still pay the deployment fee via the `X-Payment` header.

### Topup (Credit Recharge)

```bash theme={null}
curl -X PUT "https://api.x402layer.cc/agent/endpoints?slug=my-agent-api&action=topup" \
  -H "X-Enterprise-Key: sgl_ent_your_api_key_here" \
  -H "X-Payment: <x402-payment-payload>"
```

***

## MCP Server

For agent-native integration, your agents can also connect to the Singularity MCP server directly:

**Endpoint:** `https://mcp.x402layer.cc/mcp`

Pass your enterprise slug as a parameter in MCP tool calls:

```json theme={null}
{
  "enterprise_partner_slug": "your-slug"
}
```

This routes the action through your enterprise program with the same revenue split and pricing overrides.

***

## Error Responses

All errors follow a consistent format:

```json theme={null}
{
  "error": "Description of what went wrong"
}
```

| Status | Meaning                                        |
| ------ | ---------------------------------------------- |
| `401`  | Missing or invalid API key                     |
| `403`  | Insufficient scope                             |
| `404`  | Resource not found                             |
| `429`  | Rate limited (120 requests/minute per partner) |
| `500`  | Server error                                   |

***

## Rate Limits

Enterprise API requests are rate-limited to **120 requests per minute** per partner. This limit applies across all API keys for the same partner. If you exceed the limit, you'll receive a `429 Too Many Requests` response.
