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

# Edge Compute Quick Start

> Deploy serverless functions on Telnyx Edge Compute in under 5 minutes.

## Tutorial Objectives

This tutorial covers learning the basic Edge Compute development workflow.

## Prerequisites

* **A Telnyx account with API access** - [Sign up here](https://telnyx.com/sign-up) if needed.
* **Command line familiarity** - Requires Terminal (macOS/Linux) or Command Prompt (Windows).
* **Time requirement** - This guide takes approximately 5 minutes to complete.

## Install the CLI

### Download Binary

Check out the [edge-compute repo](https://github.com/team-telnyx/edge-compute) and download the latest release from the [releases page](https://github.com/team-telnyx/edge-compute/releases).

Extract the archive and add the binary to your PATH:

Example for Linux/macOS:

```bash theme={null}
# Download and extract
tar -xzf telnyx-edge-*.tar.gz

# Install to system PATH
sudo mv telnyx-edge /usr/local/bin/

# Verify installation
telnyx-edge --help
```

## Authenticate

### Option 1: OAuth (Recommended)

Authenticate using OAuth with your Telnyx account:

```bash theme={null}
telnyx-edge auth login
```

This will open your browser to complete authentication.

### Option 2: API Key

Alternatively, authenticate with a Telnyx API key:

```bash theme={null}
telnyx-edge auth api-key set YOUR_API_KEY
```

### Verify Authentication

Check your authentication status:

```bash theme={null}
telnyx-edge auth status
```

## Create a Function

Create a simple "Hello World" function. Choose your preferred language:

<Tabs>
  <Tab title="Go">
    ```bash theme={null}
    telnyx-edge new-func --language=go --name=hello-world
    ```

    This creates a new directory with the function:

    ```
    hello-world/
    ├── func.toml    # Function configuration
    ├── go.mod       # Go dependencies
    └── handler.go   # Your function code
    ```

    ### Function Code

    The generated Go function uses `package function` with a `Handle` function:

    ```go theme={null}
    package function

    import (
        "encoding/json"
        "io"
        "log"
        "net/http"
    )

    type Response struct {
        Message string `json:"message"`
        Status  string `json:"status"`
    }

    func Handle(w http.ResponseWriter, r *http.Request) {
        log.Printf("Serving request: %s %s", r.Method, r.URL.Path)

        response := Response{
            Message: "Hello from Telnyx Edge Compute!",
            Status:  "success",
        }

        w.Header().Set("Content-Type", "application/json")
        json.NewEncoder(w).Encode(response)
    }
    ```
  </Tab>

  <Tab title="JavaScript">
    ```bash theme={null}
    telnyx-edge new-func --language=js --name=hello-world
    ```

    This creates a new directory with the function:

    ```
    hello-world/
    ├── func.toml        # Function configuration
    ├── package.json     # Node.js dependencies
    └── index.js         # Your function code
    ```

    ### Function Code

    The generated JavaScript function uses a raw HTTP server:

    ```javascript theme={null}
    const http = require('http');

    const server = http.createServer((req, res) => {
        // Health endpoints for Knative probes
        if (req.url === '/health/liveness' || req.url === '/health/readiness') {
            res.writeHead(200, { 'Content-Type': 'text/plain' });
            return res.end('ok');
        }

        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end(JSON.stringify({
            message: 'Hello from Telnyx Edge Compute!',
            status: 'success',
        }));
    });

    server.listen(8080);
    ```
  </Tab>

  <Tab title="TypeScript">
    ```bash theme={null}
    telnyx-edge new-func --language=ts --name=hello-world
    ```

    This creates a new directory with the function:

    ```
    hello-world/
    ├── func.toml        # Function configuration
    ├── package.json     # Node.js dependencies
    ├── tsconfig.json    # TypeScript configuration
    └── index.ts         # Your function code
    ```

    ### Function Code

    The generated TypeScript function uses a raw HTTP server:

    ```typescript theme={null}
    import * as http from 'http';

    const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
        // Health endpoints for Knative probes
        if (req.url === '/health/liveness' || req.url === '/health/readiness') {
            res.writeHead(200, { 'Content-Type': 'text/plain' });
            return res.end('ok');
        }

        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end(JSON.stringify({
            message: 'Hello from Telnyx Edge Compute!',
            status: 'success',
        }));
    });

    server.listen(8080);
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
    telnyx-edge new-func --language=python --name=hello-world
    ```

    This creates a new directory with the function:

    ```
    hello-world/
    ├── function/        # Your function code
    │   └── __init__.py
    ├── pyproject.toml   # Python dependencies
    └── func.toml        # Function configuration
    ```

    ### Function Code

    The generated Python function uses ASGI protocol with a factory pattern:

    ```python theme={null}
    # function/func.py
    import json

    def new():
        """Factory that returns a Function instance"""
        return Function()

    class Function:
        async def handle(self, scope, receive, send):
            # Parse the request
            method = scope.get("method", "GET")
            path = scope.get("path", "/")

            # Build response
            response = {
                "message": "Hello from Telnyx Edge Compute!",
                "status": "success"
            }

            # Send response using ASGI protocol
            await send({
                "type": "http.response.start",
                "status": 200,
                "headers": [
                    [b"content-type", b"application/json"],
                ],
            })
            await send({
                "type": "http.response.body",
                "body": json.dumps(response).encode(),
            })
    ```

    The entry point is `new()` which returns a `Function` instance.
  </Tab>

  <Tab title="Java (Quarkus)">
    ```bash theme={null}
    telnyx-edge new-func --language=quarkus --name=hello-world
    ```

    This creates a new directory with the function:

    ```
    hello-world/
    ├── src/main/java/    # Your function code
    ├── pom.xml           # Maven dependencies
    └── func.toml         # Function configuration
    ```

    ### Function Code

    The generated Java function uses Quarkus Funqy with Input/Output beans:

    ```java theme={null}
    package functions;

    import io.quarkus.funqy.Funq;

    public class Function {

        @Funq
        public Output function(Input input) {
            String defaultMessage = "Hello from Telnyx Edge Compute!";
            
            if (input == null || input.getMessage() == null) {
                return new Output(defaultMessage);
            }
            
            return new Output(input.getMessage());
        }
    }
    ```
  </Tab>
</Tabs>

## Deploy the Function

Navigate to the function directory and deploy:

```bash theme={null}
cd hello-world
telnyx-edge ship
```

The CLI will:

1. Validate your function structure.
2. Check authentication.
3. Package your function files.
4. Upload to Telnyx Edge infrastructure.
5. Deploy across edge locations.

You'll see output like:

```
Deploying function 'hello-world'...
✓ Function validated successfully
✓ Authentication verified
✓ Files packaged (2.3 KB)
✓ Upload complete
✓ Function deployed successfully

Function ID: func-abc123def456
Status: Active
```

## Test the Function

Your function is now deployed and accessible via HTTP. Functions are accessible at URLs following this pattern:

`https://{funcName}-{orgId}.telnyxcompute.com`

Test your deployed function:

```bash theme={null}
curl https://hello-world-abc123.telnyxcompute.com \
  -H "Content-Type: application/json" \
  -d '{"test": "data"}'
```

Response:

```json theme={null}
{
  "message": "Hello from Telnyx Edge Compute!",
  "status": "success"
}
```

## Success! The Function is Live

Your function is now running and ready to handle HTTP requests. Functions automatically scale based on demand.

## Function Anatomy

Every Telnyx Edge Compute function consists of three essential components:

### Function Code

The main application code that handles HTTP requests and responses:

```go theme={null}
// Go example
package function

import (
    "encoding/json"
    "net/http"
)

func Handle(w http.ResponseWriter, r *http.Request) {
    json.NewEncoder(w).Encode(map[string]string{
        "message": "Hello from the edge",
    })
}
```

```javascript theme={null}
// JavaScript example
const http = require('http');

http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ message: 'Hello from the edge' }));
}).listen(8080);
```

```typescript theme={null}
// TypeScript example
import * as http from 'http';

http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ message: 'Hello from the edge' }));
}).listen(8080);
```

```python theme={null}
# Python example
class Function:
    async def handle(self, scope, receive, send):
        await send({
            "type": "http.response.start",
            "status": 200,
            "headers": [[b"content-type", b"application/json"]],
        })
        await send({
            "type": "http.response.body",
            "body": b'{"message": "Hello from the edge"}',
        })
```

```java theme={null}
// Java (Quarkus Funqy) example
package functions;

import io.quarkus.funqy.Funq;

public class Function {
    @Funq
    public Output function(Input input) {
        return new Output("Hello from the edge");
    }
}
```

### Runtime Dependencies

Language-specific dependency files that define required packages:

```mod theme={null}
// go.mod (Go)
module my-edge-function

go 1.21
```

```json theme={null}
// package.json (JavaScript/TypeScript)
{
  "name": "my-edge-function",
  "version": "1.0.0",
  "main": "index.js"
}
```

```toml theme={null}
# pyproject.toml (Python)
[project]
name = "my-edge-function"
version = "0.1.0"
dependencies = []
```

```xml theme={null}
<!-- pom.xml (Java/Quarkus) -->
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-funqy</artifactId>
</dependency>
```

### Function Configuration

The `func.toml` file that defines deployment and runtime configuration:

```toml theme={null}
[edge_compute]
func_id = "func-abc123def456"
func_name = "hello-world"

[env_vars]
MY_KEY = "VAL"
```

## Next Steps

Now that your function is deployed, explore these topics to go deeper:

* **[Runtime APIs](/docs/edge-compute/runtime)** - Request/response patterns and the platform interface.
* **[Execution Model](/docs/edge-compute/runtime/execution-model)** - Function lifecycle, cold starts, and container behavior.
* **[Configuration](/docs/edge-compute/configuration)** - Environment variables, secrets, and bindings.
* **[Local Development](/docs/edge-compute/development)** - Build, test, and debug functions locally.
* **[CLI Reference](/docs/edge-compute/reference/cli)** - All available CLI commands.
