# Playground UI (Frontend)

### 🧱 Playground Features

* Input prompt
* Model selector (or auto)
* Task selector
* Live response
* Cost display
* Model used

***

### ⚛️ Example (React / Next.js)

```tsx
"use client"

import { useState } from "react"

export default function Playground() {
  const [input, setInput] = useState("")
  const [output, setOutput] = useState("")
  const [loading, setLoading] = useState(false)

  async function runAI() {
    setLoading(true)

    const res = await fetch("/api/ai", {
      method: "POST",
      body: JSON.stringify({
        task: "text-generation",
        input,
      }),
    })

    const data = await res.json()
    setOutput(data.output)
    setLoading(false)
  }

  return (
    <div className="p-6 max-w-2xl mx-auto space-y-4">

      <h1 className="text-2xl font-bold">AI Playground</h1>

      <textarea
        className="w-full p-3 border"
        placeholder="Ask anything..."
        value={input}
        onChange={(e) => setInput(e.target.value)}
      />

      <button onClick={runAI} className="px-4 py-2 bg-black text-white">
        {loading ? "Running..." : "Run AI"}
      </button>

      {output && (
        <div className="p-4 border bg-gray-100">
          {output}
        </div>
      )}
    </div>
  )
}
```

***

### 🔌 Backend Route (Next.js)

```ts
export async function POST(req: Request) {
  const body = await req.json()

  const res = await fetch("https://api.ai1net.io/v1/ai/request", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: process.env.AI1NET_KEY!,
    },
    body: JSON.stringify(body),
  })

  return Response.json(await res.json())
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ai1net.xyz/for-developers/playground-ui-frontend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
