Quick Start With API
Start quickly with Clarifai API in a few simple steps
Clarifai provides a robust API designed to get you up and running quickly. With just a few lines of code, you can bring your AI projects to life within minutes.
Step 1: Sign Up or Log In
Start by logging into your existing Clarifai account, or sign up for a new one to unlock access to the platform’s powerful AI capabilities. New users receive free operations to help kickstart their exploration.
Step 2: Get a PAT Key
To authenticate your connection to Clarifai, you’ll need a Personal Access Token (PAT). You can obtain one from your personal settings page by navigating to the Security section.
You can then set the PAT as an environment variable using CLARIFAI_PAT
.
- Unix-Like Systems
- Windows
export CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
set CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
Step 3: Install Your Preferred SDK
You can connect to the Clarifai API using the method that best fits your development environment:
-
Python SDK – Seamlessly integrate with Clarifai using our Python client.
-
Node.js SDK – Use our SDK for integration in your JavaScript or TypeScript projects.
-
OpenAI client – Leverage Clarifai’s OpenAI-compatible endpoint to run inferences using the OpenAI client library.
Here's how to install your preferred package:
- Python SDK
- Node.js SDK
- Python (OpenAI)
pip install --upgrade clarifai
npm install clarifai-nodejs
pip install openai
Step 4: Get a Model
Clarifai’s Community platform offers a wide range of latest models to help you make your first API call.
You can easily find a model to use by heading to the Community homepage and exploring the Trending Models section, which showcases popular and ready-to-use options.
Note: Once you’ve found a model you'd like to use, copy its full model URL — you’ll need this when making prediction requests via the API.
Step 5: Send an API Request
For this example, let's use the GPT-4.1 model to generate text based on a given prompt.
- Python SDK
- Node.js SDK
- Python (OpenAI)
import os
from clarifai.client import Model
# Or, you can set the PAT as an environment variable instead of hardcoding it
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize with model URL
model = Model(url="https://clarifai.com/openai/chat-completion/models/gpt-4_1")
response = model.predict(prompt="What is the future of AI?")
print(response)
import { Model } from "clarifai-nodejs";
const model = new Model({
url: "https://clarifai.com/openai/chat-completion/models/gpt-4_1",
authConfig: {
pat: process.env.CLARIFAI_PAT,
},
});
const response = await model.predict({
// see available methodNames using model.availableMethods()
methodName: "predict",
prompt: "What is the future of AI?",
});
console.log(JSON.stringify(response));
// get response data from the response object
Model.getOutputDataFromModelResponse(response);
import os
from openai import OpenAI
# Initialize the OpenAI client, pointing to Clarifai's API
client = OpenAI(
base_url="https://api.clarifai.com/v2/ext/openai/v1", # Clarifai's OpenAI-compatible API endpoint
api_key=os.environ["CLARIFAI_PAT"] # Ensure CLARIFAI_PAT is set as an environment variable
)
# Make a chat completion request to a Clarifai-hosted model
response = client.chat.completions.create(
model="https://clarifai.com/openai/chat-completion/models/gpt-4_1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the future of AI?"}
],
)
# Print the model's response
print(response.choices[0].message.content)
Output Example
The future of AI is a topic of immense excitement, debate, and speculation, with potential to reshape society, economies, and human life in profound ways. Here’s a structured overview of key trends, possibilities, and challenges:
---
### **1. Technological Advancements**
- **General AI (AGI):** While current AI is narrow (specialized in specific tasks), future breakthroughs could lead to systems with human-like general intelligence, capable of learning and reasoning across domains. However, this remains speculative and likely decades away.
- **Quantum Computing & AI:** Quantum computing could revolutionize AI by solving complex problems (e.g., drug discovery, optimization) exponentially faster, though practical integration is still in early stages.
- **AI in Everyday Life:** AI will become more embedded in daily routines—smart homes, personalized healthcare, autonomous vehicles, and AI-driven education tools will become ubiquitous.
---
### **2. Economic and Societal Impact**
- **Productivity Gains:** AI could automate repetitive tasks, boost efficiency in industries like manufacturing, logistics, and services, potentially driving economic growth.
- **Job Displacement vs. Creation:** While some jobs may be replaced (e.g., routine-based roles), new roles in AI development, ethics, and oversight will emerge. The transition may require significant reskilling efforts.
- **Global Inequality:** Access to AI tools could widen the gap between developed and developing nations, raising concerns about "AI colonialism" or monopolies by tech giants.
---
### **3. Ethical and Governance Challenges**
- **Bias and Fairness:** AI systems may perpetuate or amplify existing biases if trained on flawed data, requiring robust frameworks for fairness and accountability.
- **Privacy and Surveillance:** Widespread AI adoption (e.g.,
Congratulations — you've just gotten started with the Clarifai platform!
Click here to learn more about how to make inference requests using our API. You'll discover how to list all the available inference methods defined in a model's configuration, generate example code, leverage our Compute Orchestration capabilities for various types of inference requests, and more.