Integration with Val.town

Val.town is a platform where you can create and deploy serverless JavaScript functions called VALs. These functions can be exposed as HTTP endpoints and integrated with Inferable to create powerful AI agents.

Key Features

  • Serverless Functions: Create and deploy JavaScript functions without managing infrastructure
  • HTTP Endpoints: Expose your VALs as HTTP endpoints that Inferable can interact with
  • Secret Management: Keep your API keys and sensitive data secure within your VALs
  • Instant Deployment: Changes to your VALs are instantly available

Building a VAL that works with Inferable

1

Create a VAL

Create a VAL on Val.town that exposes an HTTP endpoint

2

Install the Integration

Install the Val.town integration from your Inferable cluster, and provide the VAL’s public URL

3

Chat with your VAL

Start chatting with your VAL through Inferable

Example VAL

Here’s an example of a simple VAL that provides mathematical operations:

import { InferableService } from "jsr:@inferable/valtown-adapter";

const service = new InferableService({
  description: "My functions",
  token: "sk-inf-val-xxxx", // Optional: Add a token to secure your endpoint.
});

service.registerFunction({
  name: "sum",
  description: "Sum two numbers",
  handler: (input: { a: number; b: number }) =>
    Promise.resolve(input.a + input.b),
  input: {
    type: "object",
    properties: {
      a: { type: "number" },
      b: { type: "number" },
    },
    required: ["a", "b"],
  },
});

const server = service.getServer();

export default server;

End-to-end Demo

Watch an end-to-end demo of how to create and integrate a VAL with Inferable.

Authentication

To secure your VAL, you can add a token to the InferableService constructor. Your cluster val.town integration page will provide you with a token. For more information, see the Valtown Authentication page.

Security

Since Inferable cannot read the source code of your VALs:

  • All sensitive data (API keys, credentials) remains secure within your VAL
  • Only the data you explicitly return is accessible to Inferable
  • Your business logic remains private

How It Works Under the Hood

The Val.town integration is powered by the @inferable/valtown-adapter JSR package, which provides a lightweight server implementation for handling function registration and execution.

Core Components

  1. InferableService Class: The main class that manages function registration and request handling. It provides:

    • Function registration with metadata and input validation
    • HTTP server implementation with /meta and /exec/functions/{functionName} endpoints
    • Optional authentication support
  2. Request Flow:

    • /meta endpoint returns service description and registered functions
    • /exec/functions/{functionName} handles function execution with input validation
    • All responses are JSON-formatted with appropriate HTTP status codes

Authentication Flow

The adapter supports optional authentication using a Bearer token:

const service = new InferableService({
  description: "My functions",
  token: "sk-inf-val-xxxx", // Optional authentication token
});

When authentication is enabled:

  1. Each request is checked for a valid Bearer token
  2. Requests without valid tokens receive a 401 Unauthorized response
  3. Token verification happens before any function execution

When authentication is not enabled, the adapter will not check for a token. (This is not recommended for production environments.)

More information here: https://github.com/inferablehq/inferable/tree/main/adapters/valtown-adapter