• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
project logo

templates

openai-agents

Template to use the OpenAI Agents SDK
Public
Like
1
openai-agents
Home
Code
3
README.md
H
main.ts
test.ts
Branches
4
Pull requests
Remixes
1
History
Environment variables
1
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
11/20/2025
Viewing readonly version of main branch: v18
View latest version
README.md

OpenAI Agents Template

A Val Town template for creating HTTP endpoints powered by the OpenAI Agents SDK.

Getting Started

1. Set Your OpenAI API Key

Add your OpenAI API key to the val's environment variables:

  1. Go to the val settings
  2. Find the OPENAI_API_KEY environment variable
  3. Enter your OpenAI API key (get one at https://platform.openai.com/api-keys)

2. Customize Your Agent

Edit the agent configuration in main.ts:

const agent = new Agent({ name: "History Tutor", // Change to your agent's name instructions: "You provide assistance with historical queries...", // Customize instructions model: "gpt-4o", // Choose your model apiKey: Deno.env.get("OPENAI_API_KEY"), });

3. Use Your Agent

Send POST requests to your val endpoint:

curl -X POST https://your-username-your-val-name.web.val.run \ -H "Content-Type: application/json" \ -d '{"message": "Your question here"}'

Request format:

{ "message": "Tell me about the American Revolution" }

Response format:

{ "response": "The American Revolution was a colonial revolt..." }

Error Handling

The endpoint returns appropriate error responses:

  • 405 Method Not Allowed: Only POST requests are accepted
  • 400 Bad Request: Message field is missing or invalid
  • 500 Internal Server Error: Error running the agent

Learn More

  • OpenAI Agents SDK Documentation
  • OpenAI Agents Quickstart
  • Val Town Documentation
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.