openapi: 3.0.3
info:
  title: Picarta Image Geolocalization API
  description: |
    ## Overview

    The Picarta API predicts where a photo was taken from its content and/or embedded metadata. Provide an image from a local file or a URL and get back the city, province, country, GPS coordinates and a confidence score for each prediction.

    ## Authentication

    The API is available to **Enterprise accounts only**. To request access, email [info@picarta.ai](mailto:info@picarta.ai) with your company name and use case. Once approved, log in and generate your API token from your account page.
  version: 1.0.0
  contact:
    name: Picarta Support
    email: info@picarta.ai
    url: https://picarta.ai

servers:
  - url: https://api.picarta.ai/v1
    description: Production

tags:
  - name: Installation
    description: |
      For Python, we recommend using the official [`picarta`](https://pypi.org/project/picarta/) package:

      ```bash
      pip install picarta
      ```
  - name: Endpoints
  - name: Search Priority
    description: |
      When using location filters, the API searches in this order:
      1. **Admin2 + Admin1 + Country** (if all provided and supported)
      2. **Admin1 + Country** (if both provided and admin1 is supported)
      3. **Country** (if only country provided, or admin1 not supported)
      4. **Worldwide** (if no location filters provided)
  - name: No Location Found
    description: |
      When using location filters, the API may not find a location within the search area. The response then has an empty `topk_predictions_dict` and a `message` field. **No credits are deducted for this search.**

      If you get this response, try enlarging the search radius or searching in a different area.
  - name: Additional Notes
    description: |
      - `topk_predictions_dict["1"]` is the top result, also returned as `city`, `province`, `ai_country`, `ai_lat`, `ai_lon` and `ai_confidence`.
      - If the image has EXIF data, the response can also include `exif_lat`, `exif_lon` and `exif_country`.
  - name: Contact
    description: |
      - Email: [info@picarta.ai](mailto:info@picarta.ai)
      - Discord: [Join our Discord channel](https://discord.gg/g5BAd2UFbs)
      - Feedback: [API Feedback Survey](https://forms.gle/JokVe1ZRKP1hjsA49)

paths:
  /geolocalize:
    post:
      tags: [Endpoints]
      summary: Predict the location of an image
      description: |
        If the image has GPS EXIF data, it is returned directly. Otherwise the AI predicts the location.

        Use `GET /admin1/{country_code}` and `GET /admin2/{country_code}/{admin1}` to list supported regions.
      x-codeSamples:
        - lang: python
          label: picarta package
          source: |
            from picarta import Picarta

            localizer = Picarta("YOUR_API_TOKEN")
            result = localizer.localize(
                img_path="https://upload.wikimedia.org/wikipedia/commons/8/83/San_Gimignano_03.jpg",
                top_k=3,
                country_code="IT",
                admin1="Toscana",
            )
            print(result)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [TOKEN, IMAGE]
              properties:
                TOKEN:
                  type: string
                  description: Your API token.
                IMAGE:
                  type: string
                  description: Base64-encoded image or image URL.
                TOP_K:
                  type: integer
                  minimum: 1
                  maximum: 10
                  default: 10
                  description: Number of predictions to return.
                COUNTRY_CODE:
                  type: string
                  example: IT
                  description: 2-letter country code to restrict the search.
                ADMIN1:
                  type: string
                  example: Toscana
                  description: Region/state name. Requires `COUNTRY_CODE`. Ignored if not supported.
                ADMIN2:
                  type: string
                  description: County/district name. Requires `COUNTRY_CODE` and `ADMIN1`. Supported for some countries only.
                Center_LATITUDE:
                  type: number
                  example: 43.464
                  description: Latitude of the search area center.
                Center_LONGITUDE:
                  type: number
                  example: 11.038
                  description: Longitude of the search area center.
                RADIUS:
                  type: integer
                  maximum: 25
                  example: 25
                  description: Search radius in km around the center point (max 25).
                CONTEXT:
                  type: string
                  maxLength: 500
                  example: Medieval hill town in Italy
                  description: Free-text hints about the photo.
            example:
              TOKEN: YOUR_API_TOKEN
              IMAGE: https://upload.wikimedia.org/wikipedia/commons/8/83/San_Gimignano_03.jpg
              TOP_K: 3
              COUNTRY_CODE: IT
              ADMIN1: Toscana
      responses:
        '200':
          description: |
            Location predictions. If no location is found within the requested search area,
            `topk_predictions_dict` is empty, `message` is set, and **no credits are deducted**.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GeolocalizeResponse'
              examples:
                Location:
                  summary: Location found
                  value:
                    topk_predictions_dict:
                      '1':
                        address: {city: San Gimignano, country: Italy, province: Tuscany}
                        confidence: 0.9429
                        gps: [43.4672, 11.0435]
                    ai_confidence: 0.9429
                    ai_country: Italy
                    ai_lat: 43.4672
                    ai_lon: 11.0435
                    city: San Gimignano
                    province: Tuscany
                    camera_maker: NIKON CORPORATION
                    camera_model: NIKON D200
                    timestamp: '2010:09:21 12:04:46'
                No_location:
                  summary: No Location in search area
                  value:
                    topk_predictions_dict: {}
                    camera_maker: NIKON CORPORATION
                    camera_model: NIKON D200
                    timestamp: '2010:09:21 12:04:46'
                    message: No location was found within the specified search area. No credits were deducted from your account.
        '400':
          description: Invalid token, no API access, missing/unreadable image, or image too large.
          content:
            application/json:
              schema: {$ref: '#/components/schemas/Error'}
              example: {error: Image is too large.}
            text/plain:
              schema: {type: string}
              example: Incorrect access token.
        '429':
          description: Rate limit exceeded (60 requests/minute).
        '500':
          description: Temporary server error. Retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /admin1/{country_code}:
    get:
      tags: [Endpoints]
      summary: List supported admin1 regions
      x-codeSamples:
        - lang: python
          label: picarta package
          source: |
            from picarta import Picarta

            print(Picarta("YOUR_API_TOKEN").get_admin1_regions("IT"))
      parameters:
        - name: country_code
          in: path
          required: true
          schema: {type: string, example: IT}
      responses:
        '200':
          description: Supported regions. Empty list with `message` if the country supports country-level search only.
          content:
            application/json:
              schema:
                type: object
                properties:
                  country_code: {type: string}
                  admin1_regions: {type: array, items: {type: string}}
                  message: {type: string}
              example:
                country_code: IT
                admin1_regions: [Abruzzo, Basilicata, Calabria, Campania, Emilia-Romagna, Friuli Venezia Giulia, Lazio, Liguria, Lombardia, Marche, Molise, Piemonte, Puglia, Sardegna, Sicilia, Toscana, Trentino-Alto Adige, Umbria, "Valle d'Aosta", Veneto]
        '404':
          description: Country not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

  /admin2/{country_code}/{admin1}:
    get:
      tags: [Endpoints]
      summary: List supported admin2 regions
      parameters:
        - name: country_code
          in: path
          required: true
          schema: {type: string, example: US}
        - name: admin1
          in: path
          required: true
          schema: {type: string, example: Massachusetts}
      responses:
        '200':
          description: Supported admin2 regions. Empty list with `message` if not supported.
          content:
            application/json:
              schema:
                type: object
                properties:
                  country_code: {type: string}
                  admin1: {type: string}
                  admin2_regions: {type: array, items: {type: string}}
                  message: {type: string}
              example:
                country_code: US
                admin1: Massachusetts
                admin2_regions: [Barnstable, Berkshire, Bristol, Dukes, Essex, Franklin, Hampden, Hampshire, Middlesex, Nantucket, Norfolk, Plymouth, Suffolk, Worcester]

components:
  schemas:
    Prediction:
      type: object
      properties:
        address:
          type: object
          properties:
            city: {type: string}
            province: {type: string}
            country: {type: string}
        confidence: {type: number}
        gps:
          type: array
          items: {type: number}
          description: '[latitude, longitude]'
    GeolocalizeResponse:
      type: object
      properties:
        topk_predictions_dict:
          type: object
          additionalProperties: {$ref: '#/components/schemas/Prediction'}
          description: Predictions keyed by rank ("1" is the best).
        ai_country: {type: string, description: Top-1 predicted country.}
        province: {type: string, description: Top-1 predicted province.}
        city: {type: string, description: Top-1 predicted city.}
        ai_lat: {type: number, description: Top-1 predicted latitude.}
        ai_lon: {type: number, description: Top-1 predicted longitude.}
        ai_confidence: {type: number, description: Top-1 confidence.}
        exif_lat: {type: number, description: 'Latitude from EXIF, if present.'}
        exif_lon: {type: number, description: 'Longitude from EXIF, if present.'}
        exif_country: {type: string, description: 'Country from EXIF, if present.'}
        camera_maker: {type: string}
        camera_model: {type: string}
        timestamp: {type: string, description: Capture time from EXIF.}
        message: {type: string, description: Present when no location is found in the search area.}
    Error:
      type: object
      properties:
        error: {type: string}
