A Fun Guide for Young Coders 👨💻👩💻
Imagine you're at a restaurant. You don't go into the kitchen to make your own food, right? Instead:
"I'd like a pizza please!"
They tell the chef your order
Yummy pizza arrives at your table! 🍕
An API (Application Programming Interface) works just like that waiter! It takes your request, sends it to a computer (the kitchen), and brings back the answer!
Nyata AI API is like a super smart waiter that knows everything about Bristol! You can ask it questions like "Where can I find free food?" and it will bring back helpful answers! 🎉
Before we start coding, let's learn some important words:
What is an API Key?
JSON is like a organized way to write information. Think of it like filling out a form!
If you wrote about yourself on paper, it might look like this:
In JSON, that same information looks like this:
{
// This is called a JSON object
// Each line has a "name" and a "value"
"name": "Alex", // Text goes in quotes
"age": 12, // Numbers don't need quotes
"favouriteColour": "Blue"
}
{ and } to wrap everything"quotes" around names and text: between the name and value, between each item (but not after the last one!)Now let's see how to talk to Nyata AI! Here's what we need:
https://ai.mottatracking.com/external_api.php
You get this from the API Dashboard
What you want to ask the AI
When we send a message to Nyata AI, it looks like this:
{
// Tell the API which AI model to use
"model": "ft:gpt-4.1-mini-2025-04-14:nyata:bristol:ChciyaQP",
// Our conversation with the AI
"messages": [
{
"role": "user", // "user" means it's from you!
"content": "Where can I find free food in Bristol?"
}
]
}
And the API sends back something like this:
{
"success": true, // It worked!
"message": {
"role": "assistant", // The AI is talking
"content": "There are several places in Bristol where you can find free meals..."
}
}
Let's create a simple web page where you can chat with Nyata AI!
You'll need a text editor like Notepad (Windows), TextEdit (Mac), or VS Code. You'll also need an API key from the dashboard!
Step 1: Create a new file called my-nyata-chat.html
Step 2: Copy this code into your file:
<!-- This tells the browser it's an HTML page -->
<!DOCTYPE html>
<html>
<head>
<!-- The title shows in the browser tab -->
<title>My Nyata AI Chat</title>
<!-- This makes our page look nice -->
<style>
/* Make the body look nice */
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #f0f0f0;
}
/* Style our title */
h1 {
color: #4F46E5;
text-align: center;
}
/* Style the text box */
#question {
width: 100%;
padding: 15px;
font-size: 16px;
border: 2px solid #4F46E5;
border-radius: 10px;
margin-bottom: 10px;
}
/* Style the button */
#askButton {
width: 100%;
padding: 15px;
font-size: 18px;
background-color: #4F46E5;
color: white;
border: none;
border-radius: 10px;
cursor: pointer;
}
/* Make button change when you hover */
#askButton:hover {
background-color: #4338CA;
}
/* Style the answer box */
#answer {
margin-top: 20px;
padding: 20px;
background-color: white;
border-radius: 10px;
border: 1px solid #ddd;
min-height: 100px;
}
</style>
</head>
<body>
<!-- Our page title -->
<h1>🤖 Ask Nyata AI</h1>
<!-- Text box for typing questions -->
<input
type="text"
id="question"
placeholder="Ask me anything about Bristol..."
>
<!-- Button to send the question -->
<button id="askButton" onclick="askNyata()">
Ask Nyata! 🚀
</button>
<!-- Box where the answer will appear -->
<div id="answer">
Your answer will appear here...
</div>
<!-- This is our JavaScript code -->
<script>
// 🔑 PUT YOUR API KEY HERE!
const API_KEY = "your_api_key_here";
// 🌐 This is the API address
const API_URL = "https://ai.mottatracking.com/external_api.php";
// This function runs when you click the button
async function askNyata() {
// Step 1: Get the question from the text box
const questionBox = document.getElementById("question");
const userQuestion = questionBox.value;
// Step 2: Check if they typed something
if (userQuestion === "") {
alert("Please type a question first!");
return;
}
// Step 3: Show "Loading..." while we wait
const answerBox = document.getElementById("answer");
answerBox.innerHTML = "🤔 Thinking...";
// Step 4: Send the question to the API
try {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": API_KEY
},
body: JSON.stringify({
model: "ft:gpt-4.1-mini-2025-04-14:nyata:bristol:ChciyaQP",
messages: [{
role: "user",
content: userQuestion
}]
})
});
// Step 5: Get the answer from the API
const data = await response.json();
// Step 6: Show the answer! (OpenAI-style response)
if (data.choices && data.choices.length > 0) {
answerBox.innerHTML = "🤖 " + data.choices[0].message.content;
} else {
answerBox.innerHTML = "❌ Oops! Something went wrong.";
}
} catch (error) {
// If there's an error, show a message
answerBox.innerHTML = "❌ Error: " + error.message;
}
}
</script>
</body>
</html>
Let's break down the JavaScript code step by step:
// This is like saving important information in boxes
// Box 1: Your special password
const API_KEY = "your_api_key_here";
// Box 2: The address of Nyata AI
const API_URL = "https://ai.mottatracking.com/external_api.php";
const means "constant" - it creates a box that holds information and won't change. Like your home address - it stays the same!
// "fetch" is like sending a letter
const response = await fetch(API_URL, {
// POST means we're sending information
method: "POST",
// Headers are like writing your return address
headers: {
"Content-Type": "application/json", // We're sending JSON
"X-API-Key": API_KEY // Our password
},
// Body is the actual letter content
body: JSON.stringify({
model: "ft:gpt-4.1-mini-2025-04-14:nyata:bristol:ChciyaQP",
messages: [{
role: "user",
content: userQuestion
}]
})
});
await means "wait here until you get an answer." It's like waiting for your pizza to be delivered before you can eat it! 🍕
// Convert the response to something we can read
const data = await response.json();
// Check if it worked (OpenAI-style response)
if (data.choices && data.choices.length > 0) {
// YES! Show the AI's answer
answerBox.innerHTML = "🤖 " + data.choices[0].message.content;
} else {
// Something went wrong
answerBox.innerHTML = "❌ Oops! Something went wrong.";
}
Now let's test what you've learned! Here's a working demo:
This demo needs a valid API key to work. For the demo to function, you would need to add your API key to the code!
Try these questions:
Here are some cool things you can add to make your chat even better:
Change the background color or button colors in the CSS!
/* Change the button to green */
#askButton {
background-color: #10B981; /* Green */
}
/* Or try orange! */
#askButton {
background-color: #F59E0B; /* Orange */
}
/* Or pink! */
#askButton {
background-color: #EC4899; /* Pink */
}
Show all the questions and answers, not just the last one!
// Instead of replacing, ADD to the answer box
// Get what's already there
let currentContent = answerBox.innerHTML;
// Add the new question and answer (OpenAI-style response)
answerBox.innerHTML = currentContent +
"<p><strong>You:</strong> " + userQuestion + "</p>" +
"<p><strong>Nyata:</strong> " + data.choices[0].message.content + "</p><hr>";
Let users press Enter instead of clicking the button!
// Add this at the bottom of your script
// Listen for when someone types
document.getElementById("question").addEventListener("keypress", function(event) {
// Check if they pressed Enter
if (event.key === "Enter") {
// Call our askNyata function!
askNyata();
}
});
Now that you know the basics, try creating your own Bristol Helper app!
Your mission:
A messenger between your code and other computers
A way to organize information that computers understand
Send questions and get helpful answers about Bristol!
HTML for structure, CSS for style, JavaScript for actions!
You've just learned real coding skills that professional developers use every day! Keep practicing and building cool things!
Sign up and get your special password
More detailed information for advanced users
Learn more about Nyata AI