/bolt.new-ai-integrations

Bolt.new AI and Pixabay API integration: Step-by-Step Guide 2025

Integrate Bolt.new AI with Pixabay API effortlessly—follow our step-by-step guide with practical code examples to boost your image search experience.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Bolt.new AI with Pixabay API?

 

Creating a New File for Pixabay API Integration

 
  • Create a new file in your Bolt.new project and name it pixabayApi.ts. This file will contain the TypeScript code for calling the Pixabay API.

 

Implementing the Pixabay API Code

 
  • In pixabayApi.ts, add the following code snippet. This code declares your API key and base URL, and defines an asynchronous function searchImages that calls the Pixabay API. Replace YOURPIXABAYAPI_KEY with your actual Pixabay API key.

const APIKEY: string = "YOURPIXABAYAPIKEY"; // Replace with your actual API key
const BASE_URL: string = "https://pixabay.com/api/";

export async function searchImages(query: string): Promise {
  const url: string = ${BASE_URL}?key=${API_KEY}&q=${encodeURIComponent(query)}&image_type=photo;
  const response = await fetch(url);
  if (!response.ok) {
    throw new Error("Failed to fetch images from Pixabay API");
  }
  const data = await response.json();
  return data;
}

 

Importing and Using the Pixabay API Function

 
  • In your main project file (for example, index.ts), import the searchImages function from pixabayApi.ts and use it to fetch images based on a query. Insert the following code snippet into your main file.

import { searchImages } from "./pixabayApi";

async function displayImages(): Promise {
  try {
    const result = await searchImages("cats"); // Replace "cats" with a desired search term
    console.log("Images:", result.hits);
  } catch (error) {
    console.error("Error fetching images:", error);
  }
}

// Call the function as part of your application initialization
displayImages();

 

Handling User Input for API Requests

 
  • If your project includes a user interface, you can integrate a search function that calls the Pixabay API when a user types a query or clicks a button. Create or open your UI file (for example, app.ts) and insert the following code snippet.

// Example function to handle a user's search input
async function onSearchInput(query: string): Promise {
  try {
    const result = await searchImages(query);
    // Update your UI with the fetched image results (result.hits)
    console.log("Search results:", result.hits);
  } catch (error) {
    console.error("Search error:", error);
  }
}

// Example: attach the search function to a button click event
const searchButton = document.getElementById("searchBtn");
searchButton?.addEventListener("click", () => {
  const queryInput = (document.getElementById("searchInput") as HTMLInputElement).value;
  onSearchInput(queryInput);
});

 

Managing Dependencies Without a Terminal

 
  • Since Bolt.new AI doesn’t have a terminal for installing dependencies, ensure that your environment supports the native fetch API. If your environment requires a polyfill, include it manually in your code. For example, if you need node-fetch, add the following comment and import statement at the top of your file, and ensure the polyfill code is loaded.

/*
  If your environment does not support the global fetch API, you can include a polyfill.
  For example, use node-fetch by adding the following lines at the top of your file:

  import fetch from "node-fetch";
  (Make sure to include the polyfill code within your project as Bolt.new AI doesn't have a terminal)
*/

 

Configuring Your API Key Securely

 
  • For better security, consider storing your API key in a separate configuration file rather than hardcoding it. Create a file called config.ts and add the following code snippet. Then update pixabayApi.ts to import the API key from config.ts.

// In config.ts
export const PIXABAYAPIKEY: string = process.env.PIXABAYAPIKEY || "YOURPIXABAYAPI_KEY";

// In pixabayApi.ts, replace the API_KEY declaration with:
import { PIXABAYAPIKEY } from "./config";
const APIKEY: string = PIXABAYAPI_KEY;

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022