Skip to main content

Managing projects

A project is a separate workspace inside your organisation. Each project has its own policy (allowed regions, max tokens), budget, environments and API keys. Use projects to keep dev, staging and production apart, or to separate products. (New to the idea? Read Projects first.)

Create, list, update and delete​

# List
projects = client.projects.list()

# Create
project = client.projects.create(name="My App", slug="my-app", description="Production AI")

# Update
client.projects.update(project["id"], name="My App v2")

# Delete
client.projects.delete(project["id"])

A slug is a short, web-safe name, like my-app (no spaces or odd symbols).

What if my client uses a project-scoped API key?​

A client made with a project-scoped key works inside that one project only:

  • client.projects.list() returns just the key's project.
  • client.project(id) works for that project alone. Any other project is "not found" (404).
  • The key can read the project's settings. But creating, updating or deleting projects, and changing a project's settings, needs an owner's or admin's session (403).
  • Organisation-level calls, such as client.routing.get_config() and client.keys, are refused with 403.
  • client.requests.list(), client.routing.list_history() and client.usage cover the key's project only.
  • client.requests.get() or client.routing.get_decision() on a request of another project (or of no project) is "not found" (404).

See Project-scoped API keys.

Work inside one project: the sub-client​

Once you have a project ID, client.project(id) gives you a sub-client for everything in that project.

Unlike the JavaScript SDK's nested names (proj.policy.get()), the Python client uses flat methods with a prefix:

proj = client.project("proj_abc123")

Policy​

The policy applies to every request of the project: see Policy enforcement.

set_policy() replaces the whole policy

A key you leave out is cleared. So start from get_policy(), then change what you need.

policy = proj.get_policy()
policy.update(max_tokens=4096, allowed_regions=["EU"])
proj.set_policy(**policy)

Budget​

set_budget() replaces the whole budget

Pass all three values. A missing hard_limit turns the hard limit off.

See Budget enforcement.

# hard_limit: refuse the project's requests (402 budget_exceeded) once this month's (UTC) spend reaches 500.
# alert_pct is stored; budget alerts are not sent yet.
proj.set_budget(monthly_usd=500, alert_pct=80, hard_limit=True)

budget = proj.get_budget()
print(budget["current_spend"], budget["monthly_usd"])

Environments​

environments = proj.list_environments()

env = proj.create_environment("Staging", slug="staging", is_production=False)

proj.delete_environment(env["id"])