# Quickstart

- Page: https://bytesms.com/docs/quickstart (markdown: https://bytesms.com/docs/quickstart.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

Create a Bytesms API key, send a test email, verify a domain and send your first real email — with cURL, Node.js, Python, PHP, Go and SMTP examples.

## 1. Create an API key

[Sign up](https://bytesms.com/signup), open **Dashboard → API Keys** and create a key. Keys start with `tp_live_` and are shown once — store it in a secret manager or an environment variable such as `BYTESMS_API_KEY`. See [Authentication](https://bytesms.com/docs/authentication) for the permission levels.

## 2. Send a test email right away

Before you verify a domain you can already send from `onboarding@mail.bytesms.com` but only to your own account email and to the `@test.bytesms.com` test addresses:

**cURL**

```bash
# Send a test email
curl -X POST 'https://api.bytesms.com/api/v1/emails' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"from":"Bytesms <onboarding@mail.bytesms.com>","to":["delivered@test.bytesms.com"],"subject":"Hello from Bytesms","html":"<p>It works!</p>"}'
```

**Node.js**

```js
// Send a test email
const res = await fetch("https://api.bytesms.com/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "from": "Bytesms <onboarding@mail.bytesms.com>",
    "to": [
      "delivered@test.bytesms.com"
    ],
    "subject": "Hello from Bytesms",
    "html": "<p>It works!</p>"
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Send a test email
res = requests.post(
    "https://api.bytesms.com/api/v1/emails",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "from": "Bytesms <onboarding@mail.bytesms.com>",
        "to": [
            "delivered@test.bytesms.com"
        ],
        "subject": "Hello from Bytesms",
        "html": "<p>It works!</p>"
    },
)
print(res.json())
```

**PHP**

```php
<?php

// Send a test email
$ch = curl_init("https://api.bytesms.com/api/v1/emails");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["Authorization: Bearer tp_live_xxxxxxxxx", "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode([
        'from' => 'Bytesms <onboarding@mail.bytesms.com>',
        'to' => [
            'delivered@test.bytesms.com',
        ],
        'subject' => 'Hello from Bytesms',
        'html' => '<p>It works!</p>',
    ]),
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $response, PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func main() {
	// Send a test email
	body := []byte(`{"from":"Bytesms <onboarding@mail.bytesms.com>","to":["delivered@test.bytesms.com"],"subject":"Hello from Bytesms","html":"<p>It works!</p>"}`)
	req, err := http.NewRequest("POST", "https://api.bytesms.com/api/v1/emails", bytes.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer tp_live_xxxxxxxxx")
	req.Header.Set("Content-Type", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(res.Status, string(out))
}
```

**Response**

```json
{
  "id": "cmg4k2x7a0001l8v9h3q2d5rt"
}
```

## 3. Add and verify your domain

To send to anyone else, add a domain you own. Use a subdomain such as `mail.example.com` if you want to keep sending reputation separate from your root domain.

**cURL**

```bash
# Add a domain
curl -X POST 'https://api.bytesms.com/api/v1/domains' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"name":"example.com"}'
```

**Node.js**

```js
// Add a domain
const res = await fetch("https://api.bytesms.com/api/v1/domains", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "example.com"
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Add a domain
res = requests.post(
    "https://api.bytesms.com/api/v1/domains",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "name": "example.com"
    },
)
print(res.json())
```

The response lists the DNS records to publish at your DNS provider — a DKIM `TXT` record and a return-path `CNAME` (plus recommended SPF and DMARC records). After publishing them, trigger a check:

**cURL**

```bash
# Verify the domain
curl -X POST 'https://api.bytesms.com/api/v1/domains/{domain_id}/verify' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// Verify the domain
const res = await fetch("https://api.bytesms.com/api/v1/domains/{domain_id}/verify", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# Verify the domain
res = requests.post(
    "https://api.bytesms.com/api/v1/domains/{domain_id}/verify",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

Verification is also re-checked automatically every few minutes; the domain moves from `pending` to `verified` once the DKIM record and the return path (or SPF) resolve. Details: [Domains](https://bytesms.com/docs/domains).

## 4. Send your first real email

**cURL**

```bash
# Send an email
curl -X POST 'https://api.bytesms.com/api/v1/emails' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"from":"Acme <hello@example.com>","to":["customer@gmail.com"],"subject":"Welcome to Acme","html":"<h1>Welcome!</h1><p>Thanks for signing up.</p>"}'
```

**Node.js**

```js
// Send an email
const res = await fetch("https://api.bytesms.com/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "from": "Acme <hello@example.com>",
    "to": [
      "customer@gmail.com"
    ],
    "subject": "Welcome to Acme",
    "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>"
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Send an email
res = requests.post(
    "https://api.bytesms.com/api/v1/emails",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "from": "Acme <hello@example.com>",
        "to": [
            "customer@gmail.com"
        ],
        "subject": "Welcome to Acme",
        "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>"
    },
)
print(res.json())
```

## 5. Track what happens

1. Poll `GET /api/v1/emails/{id}` — its `last_event` becomes `sent`, then `delivered` (or `bounced`).
2. Or add a [webhook endpoint](https://bytesms.com/docs/webhooks) and receive `email.delivered`, `email.bounced` and the other events as they happen.

## Other ways to send

### Bytesms SDK for TypeScript and JavaScript

The official [@bytesms/sdk](https://www.npmjs.com/package/@bytesms/sdk) package wraps the REST API with types, `{ data, error }` results, idempotency keys, automatic retries and webhook verification. It runs on Node.js 18+, Bun, Deno and edge runtimes. Details: [TypeScript SDK](https://bytesms.com/docs/sdk).

**Bytesms SDK (Node.js)**

```ts
// npm install @bytesms/sdk
import { Bytesms } from "@bytesms/sdk";

const bytesms = new Bytesms(process.env.BYTESMS_API_KEY);

const { data, error } = await bytesms.emails.send(
  {
    from: "Acme <hello@example.com>",
    to: "delivered@test.bytesms.com",
    subject: "Hello from Bytesms",
    html: "<p>It works!</p>",
  },
  { idempotencyKey: "hello-1" },
);
console.log(data ?? error);
```

### SMTP

Any SMTP client works: host `smtp.bytesms.com`, port `465` (TLS) or `587` (STARTTLS), username `bytesms`, password = your API key. The same sending rules and quotas apply; attachments are rejected. Details: [SMTP](https://bytesms.com/docs/smtp).

**Nodemailer (SMTP)**

```js
import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
  host: "smtp.bytesms.com",
  port: 465,
  secure: true, // implicit TLS; use port 587 with secure: false for STARTTLS
  auth: { user: "bytesms", pass: process.env.BYTESMS_API_KEY },
});

const info = await transporter.sendMail({
  from: "Acme <hello@example.com>",
  to: "delivered@test.bytesms.com",
  subject: "Hello from Bytesms",
  html: "<p>It works!</p>",
});
console.log(info.messageId);
```

**Laravel .env**

```ini
MAIL_MAILER=smtp
MAIL_HOST=smtp.bytesms.com
MAIL_PORT=587
MAIL_USERNAME=bytesms
MAIL_PASSWORD=tp_live_xxxxxxxxx
# Laravel 10 and older; Laravel 11+ negotiates STARTTLS on 587 by itself
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME="${APP_NAME}"
```

### Resend SDKs

The REST API is Resend-style, so the official `resend` SDKs for Node.js and Python can send through Bytesms when you point them at `https://api.bytesms.com/api/v1`. We tested sending, batch sending, retrieving an email, listing domains and error handling. Only the parameters documented here are accepted, and attachments are not supported. Other Resend SDKs and Resend endpoints that aren't in these docs are untested, so for other languages call the REST API directly (the PHP and Go tabs above).

**Resend SDK (Node.js)**

```js
import { Resend } from "resend";

// resend >= 6: pass baseUrl. Any version: set RESEND_BASE_URL=https://api.bytesms.com/api/v1 instead.
const resend = new Resend(process.env.BYTESMS_API_KEY, { baseUrl: "https://api.bytesms.com/api/v1" });

const { data, error } = await resend.emails.send({
  from: "Acme <hello@example.com>",
  to: ["delivered@test.bytesms.com"],
  subject: "Hello from Bytesms",
  html: "<p>It works!</p>",
});
console.log(data ?? error);
```

**Resend SDK (Python)**

```python
import os
import resend

resend.api_key = os.environ["BYTESMS_API_KEY"]
resend.api_url = "https://api.bytesms.com/api/v1"  # or set RESEND_API_URL

email = resend.Emails.send({
    "from": "Acme <hello@example.com>",
    "to": ["delivered@test.bytesms.com"],
    "subject": "Hello from Bytesms",
    "html": "<p>It works!</p>",
})
print(email["id"])
```

> **Warning: Keep keys on the server**
>
> Never ship an API key in browser or mobile code. For a key that can only send (and only from one domain), create a [sending-access key](https://bytesms.com/docs/authentication#permissions).
