# Requests and responses

Dates, time zones, places, languages, options and the response envelope.

## Base URL and format

```text
https://api.96astroapi.com/v1
```

Requests are `POST` with a JSON body (`Content-Type: application/json`). Capability responses are JSON, except that capabilities with dated results can answer as a [calendar file](#calendar-export-ics). A few chart capabilities include SVG drawings as strings inside the JSON, and their reference entry says so. PDFs are made by [report jobs](https://96astroapi.com/docs/jobs-and-webhooks.md).

### Discovering what is callable

`GET /v1/capabilities` needs no key. It lists every capability with its `id`, `family`, `title`, `status`, `path`, whether it is callable (`available_in_v1`), whether it is switched on right now (`enabled`) and a ready-to-send `example` body. `GET /v1/openapi.json` is the full [OpenAPI document](https://96astroapi.com/openapi/v1.json), including each operation's `x-credits`, `x-credits-by-input` (where the price follows the request) and `x-languages`.

### Chart images: format, theme and hosted URLs

**Getting the drawing.** Every capability about a chart returns its data by default. Send `"include_image": true` (with `"image_style"`: `north`, `south`, `east` or `western`) and its drawings come back too, as `images`: a list of `{ "chart", "style", "format", "svg" }`. That covers the birth-chart bundle and divisional, special lagna, Chandra Kundli, Bhav Chalit and Jaimini charts, the KP charts (birth, houses and planets, horary, transit), BNN charts and progressions, Lal Kitab and its annual and month charts, Varshaphal and Tithi Pravesh, Ashtakavarga diamonds, the Shadbala graph, the Panchang sunrise chart, Gochara with Sarvatobhadra, Ayu Milan and the matching report's charts, Compare Locations, and the mundane Kota and Sarvatobhadra chakras. A drawn answer is priced as a heavy calculation (a report keeps its own price). The [single chart endpoints](https://96astroapi.com/docs/single-endpoints.md) take the same `include_image`, and `chart-image-styles` returns drawings only, for any charts you name.

Every capability that returns chart images takes four optional fields. All of them are free: the credits are the capability's.

| Field | Values | What it does |
|---|---|---|
| `image_format` | `svg` (default), `svg_base64` or `png` | `svg` returns the SVG markup. `svg_base64` returns it as a `data:image/svg+xml;base64,...` URI (sharp at any size, ready for an `<img>` tag). `png` returns each chart as a `data:image/png;base64,...` URI, ready for an `<img>` tag, an app or an email; an object's `svg` field becomes `png`, and its `format` says `png` |
| `image_width` | 200 to 2400 (default 1000) | The width of each PNG in pixels; the height keeps the chart's proportions |
| `image_theme` | `light` (default), `dark` or `print` | `light` is the chart's own colours. `dark` draws light ink on a dark surface (the same palette as this site's dark mode). `print` is black on no background, for paper, PDFs and e-ink. Applies to SVG and PNG alike |
| `image_delivery` | `inline` (default), `url` or `both` | `url` replaces each inline image with a short-lived signed link you can put straight into `<img src>`; `both` keeps the inline image and adds the link |

**Why an SVG looks "escaped" in the raw response.** Inside JSON an SVG is a text string, so its quotes arrive as `\"` and its line breaks as `\n`. Pasting that raw text into an SVG viewer fails. Parse the JSON first (`response.json()`, `json.loads`, `json_decode`): the `svg` value you get is ordinary SVG markup. If you want something you can drop straight into `<img src>` without handling markup, ask for `"image_format": "svg_base64"` or `"png"`. In the portal, **API testing** shows each chart in the response with **Copy SVG** and **Download** buttons, and starts chart endpoints on `svg_base64`.

```json
{ "datetime": "1990-10-18T14:30:00", "timezone": "Asia/Kolkata", "latitude": 28.6139, "longitude": 77.209,
  "style": "north", "charts": ["D1", "D9"], "image_format": "png", "image_width": 800,
  "image_theme": "dark", "image_delivery": "url" }
```

With `url` or `both`, each image object gains two fields:

```json
{ "chart": "D1", "style": "north", "format": "png",
  "url": "https://api.96astroapi.com/v1/images/AbC...xyz.Q1w...e9.png",
  "url_expires_at": "2026-10-28T09:15:02Z" }
```

- **No API key is needed to fetch the link.** The signature in it is the authorisation, so you can hand it to a browser or an email client without exposing your key. The link names only the image, never your account or the birth data.
- **It expires** at `url_expires_at`, 24 hours after the call. After that it answers `410 link_expired`; call the capability again for a fresh link. A link that has been altered answers `404`.
- **Caching:** the image is served with its own `Content-Type` (`image/png` or `image/svg+xml`) and `Cache-Control: public, immutable` for the rest of the link's life, so a browser or CDN fetches it once.
- **Retention:** the rendered image is kept on our servers for 24 hours after the last request that produced it, then deleted automatically. Identical charts share one stored file. If you need an image for longer, download it and keep your own copy.
- A chart that comes as a bare string rather than an object (rare) is replaced by the link with `url`, and stays inline with `both`.
- Up to 60 images per response. The keyless try-it on this site does not create links.

On a capability without chart images, any of these fields is refused with `422 invalid_request`.

### Calendar export (ics)

Capabilities with dated results can answer as an iCalendar file (RFC 5545) that Google Calendar, Apple Calendar and Outlook import or subscribe to. Add `"format": "ics"` to the body, or send `Accept: text/calendar`:

```bash
curl https://api.96astroapi.com/v1/festivals-muhurta/vrat-calendar \
  -H "Authorization: Bearer $ASTRO_API_KEY" -H "Content-Type: application/json" \
  -d '{ "year": 2026, "observance": "ekadashi", "timezone": "Asia/Kolkata",
        "latitude": 28.6139, "longitude": 77.209, "format": "ics" }' \
  -o ekadashi-2026.ics
```

The response is `text/calendar; charset=utf-8` with `Content-Disposition: attachment`. It costs the same credits as the JSON call, and the `X-Request-Id`, `X-Credits-Used` and rate-limit headers are as usual. `format: "json"` (the default) wins over the `Accept` header.

| Capability | Events |
|---|---|
| `planetary-events` | Sign and nakshatra ingresses (Sankrantis named) and retrograde/direct stations, at the exact moment |
| `western-transit-dates` | Each exact transit-to-natal aspect, at the exact moment |
| `vrat-calendar` | Each vrat day, all day |
| `day-festivals` | Each festival on the day, all day |
| `muhurta-finder` | Each clear muhurta window, start to end (a day with no listed window becomes an all-day event) |
| `shraddha-dates` | The Varshik and Pitru Paksha shraddha days, all day |
| `eclipses` | Each eclipse from first to last contact, with local visibility and Sutak in the description; equinoxes and solstices |
| `sade-sati` | Each Sade Sati, Kantaka and Ashtama Shani spell |
| `vimshottari-dasha` | Each mahadasha and antardasha, as all-day spans |
| `lifetime-malefic-transits` | Each Saturn, Rahu and Ketu transit of a sensitive sign, as all-day spans |

How the file is written:

- **Times are UTC** (`DTSTART:20261121T023700Z`), so every calendar app shows them in its own zone. Local times in the answer are converted using the request's `timezone` or `utc_offset`.
- **Date-only items are all-day events**; exact moments (an ingress, a station) are events with a start and no end.
- **Stable UIDs.** Each event's UID comes from the capability, the place or birth details you sent, and the event itself. Importing the same calendar again, or a longer date range, updates the events instead of duplicating them; a calendar for another place or another person gets its own events.
- `meta.warnings` go into the calendar's description (`X-WR-CALDESC`).

Asking for `"format": "ics"` on a capability without a calendar export is refused with `422 invalid_request` (`field: "format"`), not charged; `Accept: text/calendar` alone is ignored there and you get JSON.

### Compact output for language models (llm)

Add `"format": "llm"` to any call to get the same answer as compact Markdown: headings, short lists and tables, with drawings and base64 left out. It is far fewer tokens than the JSON, so it suits prompts and AI agents. The response is `text/markdown; charset=utf-8`; the envelope's `meta` comes in the `X-Meta` header (JSON) and the request id in `X-Request-Id`. It costs the same credits as the JSON call.

## Date and time

Send the **local** date and time as ISO 8601 without an offset, plus an **IANA time-zone name**:

```json
{ "datetime": "1990-10-18T14:30:00", "timezone": "Asia/Kolkata" }
```

We resolve the offset for that exact date, including historical changes and daylight saving. If a local time is ambiguous (clocks went back) or does not exist (clocks went forward), you get `422 ambiguous_local_time`, with the possible offsets in `choices` when the clocks went back; send `utc_offset` to choose. We never guess.

If you only have a fixed offset, send `"utc_offset": "+05:30"` instead of `timezone`. The format is one optional sign, one or two hour digits, and optionally a colon and minutes from 00 to 59 (`+05:30`, `-03:30`, `+05:45`, `5:30`, `+5`), between `-12:00` and `+14:00`. Anything else, such as `+05:99`, `--05:30` or `+05:-30`, is refused with `422 invalid_request` and `field: "utc_offset"` before anything is calculated or charged.

## Place

`latitude` and `longitude` are decimal degrees: north and east positive, south and west negative. To find coordinates and the time zone for a place name, use the place-search capability under **Utilities**.

### Return charts: casting the chart somewhere else

`western-solar-return`, `western-lunar-returns` and `western-planetary-returns` cast the return chart at the birth place unless you send `return_place`:

```json
{ "datetime": "1990-10-18T14:30:00", "timezone": "Asia/Kolkata", "latitude": 28.6139, "longitude": 77.209,
  "target_year": 2027,
  "return_place": { "latitude": 51.5072, "longitude": -0.1276, "utc_offset": "+00:00", "timezone": "Europe/London" } }
```

`latitude`, `longitude` and `utc_offset` are required. Add an IANA `timezone` and each return takes the offset that zone had at that return's own instant (a winter return in London is +00:00, a summer one +01:00); `timezone` wins over `utc_offset` when both are sent. Without `timezone`, `utc_offset` is applied to every return in the answer, so use the zone name for a place with daylight saving. An unknown zone name is refused with `422`.

## Astrology settings

| Field | Default | Notes |
|---|---|---|
| `ayanamsha` | `lahiri` | Sidereal capabilities. The reference lists every supported value. KP capabilities default to the Krishnamurti ayanamsha when you send none (`kp-houses-planets` and the other engine-native KP capabilities accept only Krishnamurti) |
| `house_system` | per capability | Western capabilities take any of the ten systems we compute, as a one-letter code: `P` Placidus, `K` Koch, `W` whole sign, `E` equal, `C` Campanus, `R` Regiomontanus, `O` Porphyry, `M` Morinus, `T` topocentric or `B` Alcabitius. Placidus is only the default. KP capabilities always use Placidus cusps. The OpenAPI document lists each capability's values |
| `node` | `true` | `true` (osculating) or `mean` lunar node, on chart capabilities |

An unsupported value is rejected with `422`. The API never silently substitutes a default. Responses echo the settings used where they apply, for example `ayanamsha`, `node` and `house_system` in planet positions.

## Language

Each capability lists the languages it answers in: the `language` enum of its request and `x-languages` in the [OpenAPI document](https://96astroapi.com/openapi/v1.json). The four AI readings answer in 26 languages, English included. Many calculations and reports also answer in all 26: their explanatory sentences come from a catalog of pre-translated text, nothing is machine-translated at request time, and a sentence the catalog lacks stays whole in English (`meta.translation` counts them). The rest answer in English. Any request can add `labels` for translated display names of the terms in the answer (13 curated Indian languages, plus Sinhala and ten European and East Asian languages in a lighter form): see [translated labels](https://96astroapi.com/docs/languages.md#translated-labels). The [languages page](https://96astroapi.com/docs/languages.md) lists which capabilities answer in which languages.

The 26 languages are these ISO 639-1 codes:

`as bn de en es fr gu hi it ja kn ko ml mr ne nl or pa pl pt ru si ta te tr ur`

An AI reading is written by a language model in the language you ask for. Both the readings and the translated sentences are machine-assisted and have not been reviewed by native speakers. A language a capability does not support is rejected with `422 unsupported_language`, and the error's `supported` lists the ones it takes. `en` (the default) is accepted everywhere.

Field names, IDs, enum values and numbers never change with language; only display text does. `meta.language` states the language the answer is in.

## Response envelope

Every successful response has the same shape:

```json
{
  "data": { },
  "meta": {
    "request_id": "req_6e985a89a166b73ea220",
    "api_version": "v1",
    "credits_used": 3,
    "warnings": [],
    "language": "en"
  }
}
```

- **Lists are arrays.** Planets, houses and periods are arrays of objects with named fields, never objects keyed `"0"`, `"1"`.
- **Missing versus empty.** `[]` means the calculation ran and found nothing; `null` means a value does not apply, with the reason in `meta.warnings`.
- **Dates** in responses are ISO 8601 with an explicit offset.
- **`request_id`** identifies the call (`req_` and 20 hex characters). It is also in the `X-Request-Id` header of every response, including errors; quote it when you contact support.
