Set up your project
Create an API key, install the Photon client, and make your first API request.
A project holds everything your agent uses: its channels, messages, and API keys. In this guide, you create a key for your project, install the client for your language, and use them to make your first request.
Prerequisites
You need:
- A Photon Beta account. Sign up in the dashboard if you don't have one.
- One of these: Node.js 24 or later, Python 3.11 or later, Rust 1.88 or later, or Go 1.25 or later.
Choose a project
Open the Beta dashboard. Select a project in the switcher at the top of the sidebar, or create one.
Create an API key
Open API keys. Copy
the project ID under the page title. It starts with pho_prj_.
Under Create an API key, enter a name, choose how long the key lasts, and select Create key. Choose Custom, then select the permissions your code needs:
| Permission | Lets your code |
|---|---|
project:read | Read the project and receive messages. |
project:write | Send messages. |
platforms:read | Read channel settings, such as a Voice profile. Optional. |
platforms:write | Connect channels from code instead of the dashboard. Optional. |
Select Create key and copy the key. It is shown only once. If you lose it, create a new key and revoke the old one.
Full access in the Create key menu also works. It gives the key every permission in the project, which is more than these guides need.
Set environment variables
In the terminal where you will run your code, set the project ID and the key you copied:
export PHOTON_PROJECT_ID="pho_prj_REPLACE_WITH_YOUR_PROJECT_ID"
export PHOTON_API_KEY="pho_sk_REPLACE_WITH_YOUR_PROJECT_API_KEY"Install the client
Create a directory for your agent and install the client for one language. These guides use version 0.6.0.
mkdir photon-first-agent && cd photon-first-agent
npm init -y && npm pkg set type=module
npm install @photon-ai/api@0.6.0mkdir photon-first-agent && cd photon-first-agent
python3 -m venv .venv && source .venv/bin/activate
pip install photonhq-api==0.6.0cargo new photon-first-agent && cd photon-first-agent
cargo add photonhq-api@=0.6.0
cargo add tokio --features macros,rt-multi-threadmkdir photon-first-agent && cd photon-first-agent
go mod init example.com/photon-first-agent
go get github.com/photon-hq/api/packages/go@v0.6.0Make your first request
Read your project with your new key. Save this as first-request.ts,
first_request.py, src/main.rs, or first_request.go:
import { Photon } from "@photon-ai/api";
const { PHOTON_API_KEY, PHOTON_PROJECT_ID } = process.env;
if (!PHOTON_API_KEY || !PHOTON_PROJECT_ID) throw new Error("Set PHOTON_API_KEY and PHOTON_PROJECT_ID");
const photon = new Photon({
headers: { Authorization: `Bearer ${PHOTON_API_KEY}` },
});
const project = await photon.projects.get({ path: { projectId: PHOTON_PROJECT_ID } });
console.log(`Connected to ${project.name} (${project.projectId})`);import os
from photon_api import Photon
from photon_api.rpc_generated import GetProjectInput
with Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_KEY']}"}) as photon:
project = photon.projects.get(
GetProjectInput.model_validate({"path": {"projectId": os.environ["PHOTON_PROJECT_ID"]}})
)
print(f"Connected to {project.name} ({project.projectId})")use photon_ai_api::{Credential, PhotonClientBuilder, SecretString};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = SecretString::from(std::env::var("PHOTON_API_KEY")?);
let client = PhotonClientBuilder::new()
.credential("projectApiKey", Credential::Bearer(key))
.build()?;
let project = client
.get_project(std::env::var("PHOTON_PROJECT_ID")?)
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();
println!("Connected to {} ({})", project.name, project.project_id);
Ok(())
}package main
import (
"context"
"fmt"
"log"
"os"
photonapi "github.com/photon-hq/api/packages/go"
)
func main() {
client := photonapi.NewClient(photonapi.WithAPIKey(os.Getenv("PHOTON_API_KEY")))
project, err := client.Projects.Get(context.Background(), &photonapi.GetProjectParams{
ProjectID: os.Getenv("PHOTON_PROJECT_ID"),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Connected to %s (%s)\n", project.Name, project.ProjectID)
}Run it:
node first-request.tspython first_request.pycargo run --bin photon-first-agentgo run first_request.goYou should see your project's name and ID:
Connected to My project (pho_prj_...)Troubleshooting
| Error | What to check |
|---|---|
401 | The key is wrong, expired, or revoked, or PHOTON_API_KEY isn't set in this terminal. |
403 | The key belongs to another project, or it lacks project:read. |
404 | PHOTON_PROJECT_ID doesn't match the ID on the API keys page. |
Next: connect a channel
Give your agent a way to receive messages. Pick a channel: