Skip to main content
Create one client and reuse it for every call. Each endpoint in the API reference is a method on the client, and each endpoint page shows its call in all three languages.

Your first request

This program lists the projects in an organization. Set PHOTON_API_KEY to an account service key or a service identity credential, and PHOTON_ORGANIZATION_ID to the ID of an organization it can access.
If you use a service identity credential in Rust, register it as "serviceIdentityBearer" instead. See Credentials.

How calls are shaped

Methods are grouped into namespaces that follow the API paths, such as photon.organizations.projects.list. Each method takes one object with the members the endpoint declares:
  • path: path parameters, such as { organizationId }.
  • query: query parameters, such as { pageSize: 10 }.
  • headers: header parameters, under the contract’s names. Where the contract spells the header Idempotency-Key, write it idempotencyKey; other header names are written as the contract spells them, such as "idempotency-key", "content-type", and "content-length" for uploadAttachment.
  • body: the request body.
Other names are the contract’s own, which are camelCase. A method resolves to the response body, typed with the contract’s fields. An optional second argument takes { signal, headers } for one call: an AbortSignal to cancel it, and extra headers to send.
Request values are typed by the contract and sent as given. Rules such as patterns, lengths, and ranges are checked by the API, which answers with an error such as VALIDATION_FAILED when a value breaks one. See Errors.

Send a body and headers

Creating a project takes a path parameter, an Idempotency-Key header, and a JSON body. Retries and timeouts explains the idempotency key. The Rust example generates the key with the rand crate; add it with cargo add rand.

Change the base URL

The clients call https://api.photon.codes. To call another address, such as a local mock server in tests, set the base URL when you create the client.
You can also bring your own HTTP client: the fetch option in TypeScript, client= (an httpx.Client for Photon, an httpx.AsyncClient for AsyncPhoton) in Python, and reqwest_client on the Rust builder. The base URL, timeout, and retry settings still apply, except that in Rust the builder’s timeout is no longer also the connect timeout: configure that on your reqwest::Client. In Python, a client you pass in is not closed for you.