Public
Like
1
openai-agents
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.
Viewing readonly version of main branch: v10View latest version
A Val Town template for creating HTTP endpoints powered by the OpenAI Agents SDK.
Add your OpenAI API key to the val's environment variables:
- Go to the val settings
- Find the
OPENAI_API_KEYenvironment variable - Enter your OpenAI API key (get one at https://platform.openai.com/api-keys)
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"),
});
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..." }
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