![]() | ||||||||||
| Printed from wandabuilds.ai/t/sQhq
| ||||||||||
| Tutorials · Intermediate How to connect an AI API (step by step)Learn to connect an AI API from scratch: create your API key, install the SDK, store the key safely and make your first call in Python or Node.js.
An AI API is how your own program talks to a model like Claude or GPT: your code sends a question and gets the answer back, without you typing in a website. It’s the step that separates “I use AI” from “I build with AI”. In this guide you’ll connect an AI API from scratch: create your key, install the SDK and make your first call. Pick your system (Windows or Mac) with the buttons above and tap each step to open it.
1 Create your account and API keyWe’ll use the Claude (Anthropic) API as the example. The pattern is the same for OpenAI and others.
2 Add credit (billing)The key won’t work until you add a payment method and a little credit.
3 Install the SDKThe SDK is a library that makes talking to the API easy. Pick your language. You need PowerShellthe Terminal open. With Python (you need Python installed):
With Node.js (you need Node.js installed):
4 Store your API key safelyNever write the key inside your code: anyone who sees the file (or your GitHub repo) would have it. Instead, store it as an environment variable. In PowerShell (saved for your user):
Close and reopen PowerShell so it picks up the change. In the Terminal (for the current session):
To make it permanent, add that line to your The SDK reads that variable on its own, without you writing the key in the code. 5 Make your first callCreate a file and paste your language’s example. Change only the question text. Python (
Run:
Node.js (
Run:
If you see the answer printed in the terminal, you just connected your first AI API.
If something goes wrong
Security: protect your key
Ready for the next step? Learn to create your first AI agent using what you just connected. Frequently asked questionsWhat is an AI API?It's the door for your own program to talk to an AI model. Instead of typing in a website like ChatGPT or Claude, your code sends a question and gets the answer back, to automate or build apps. Do I need to know how to code to connect an AI API?A little helps, but you can copy the example in this guide and change only the question text. That already gets your first call working. How much does using an AI API cost?You pay per use, by tokens (chunks of text), not a monthly fee. For testing it's very cheap: a fast model like Claude Haiku costs around $1 per million input tokens. Confirm current prices on the official page. Is it safe to put my API key in the code?No. Store it as an environment variable (Step 4) and never upload it to GitHub. If it leaks, delete it from the console and create a new one. Should I use Python or Node.js?Either one works; this guide shows both. If you've never coded, Python is usually easier to read to start. |
