> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thebuoy.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Find nearest buoy to coordinates

> Find the closest active buoy(s) to a given latitude and longitude within a maximum distance.

Use the `limit` parameter to control how many results are returned (default: 1, max: 20).




## OpenAPI

````yaml /api-reference/openapi.json get /buoys/nearest
openapi: 3.0.3
info:
  title: The Buoy API
  version: 2.0.0
  description: >-
    **The Buoy API** — programmatic access to ocean wave buoys on The Surf Kit
    platform.


    All operations are **read-only** (`GET`). Data includes live and historical
    readings, geographic filters, chart time series, and **`GET /conditions`**
    (combined forecast, buoy reading, and tide for a point).


    ## Authentication


    Pass your API key in the `Authorization` header:


    ```

    Authorization: Bearer YOUR_API_KEY

    ```


    `GET /buoys/search` and `GET /buoys/nearest` are public (no key required).


    ## Rate limiting


    Responses include `X-RateLimit-*` headers. Exceeding your hourly quota
    returns `429 Too Many Requests`.
  contact:
    name: API Support
    email: thomas@thebuoy.app
  license:
    name: Proprietary
servers:
  - url: https://api.thebuoy.app/v2
    description: Production server (V2)
  - url: http://localhost:3000/api/v2
    description: Development server (V2)
security:
  - ApiKeyAuth: []
tags:
  - name: Buoys
    description: Real-time ocean buoy data
  - name: Satellite Passes
    description: >-
      Satellite altimeter passes over virtual buoys, and the missions behind
      them
  - name: Conditions
    description: All-in-one conditions endpoint
paths:
  /buoys/nearest:
    get:
      tags:
        - Buoys
      summary: Find nearest buoy to coordinates
      description: >
        Find the closest active buoy(s) to a given latitude and longitude within
        a maximum distance.


        Use the `limit` parameter to control how many results are returned
        (default: 1, max: 20).
      operationId: nearestBuoy
      parameters:
        - name: lat
          in: query
          required: true
          description: Latitude in decimal degrees (-90 to 90)
          schema:
            type: number
            format: float
            minimum: -90
            maximum: 90
          example: 43.5
        - name: lng
          in: query
          required: true
          description: Longitude in decimal degrees (-180 to 180)
          schema:
            type: number
            format: float
            minimum: -180
            maximum: 180
          example: -1.5
        - name: max_distance
          in: query
          description: 'Maximum search radius in kilometers (default: 150)'
          schema:
            type: number
            format: float
            default: 150
            minimum: 0
          example: 150
        - name: limit
          in: query
          description: 'Maximum number of results to return (default: 1, max: 20)'
          schema:
            type: integer
            default: 1
            minimum: 1
            maximum: 20
          example: 5
      responses:
        '200':
          description: Successful response with nearest buoy(s)
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/XRateLimitLimit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/XRateLimitRemaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/XRateLimitReset'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    description: Response when limit=1 (single buoy)
                    properties:
                      status:
                        type: string
                        example: success
                      data:
                        type: object
                        properties:
                          buoy:
                            $ref: '#/components/schemas/BuoyWithDistance'
                  - type: object
                    description: Response when limit>1 (array of buoys)
                    properties:
                      status:
                        type: string
                        example: success
                      data:
                        type: object
                        properties:
                          buoys:
                            type: array
                            items:
                              $ref: '#/components/schemas/BuoyWithDistance'
                          count:
                            type: integer
                            description: Number of buoys returned
              examples:
                single_buoy:
                  summary: Single buoy (limit=1 or default)
                  value:
                    status: success
                    data:
                      buoy:
                        id: 10
                        name: Anglet
                        lat: 43.4832
                        lng: -1.5586
                        source: Candhis
                        source_identifier: '64002'
                        distance_km: 2.5
                    meta:
                      timestamp: '2025-11-01T10:00:00Z'
                multiple_buoys:
                  summary: Multiple buoys (limit>1)
                  value:
                    status: success
                    data:
                      buoys:
                        - id: 10
                          name: Anglet
                          lat: 43.4832
                          lng: -1.5586
                          source: Candhis
                          source_identifier: '64002'
                          distance_km: 2.5
                        - id: 11
                          name: Biarritz
                          lat: 43.48
                          lng: -1.56
                          source: Candhis
                          source_identifier: '64003'
                          distance_km: 5.8
                      count: 2
                    meta:
                      timestamp: '2025-11-01T10:00:00Z'
        '400':
          $ref: '#/components/responses/BadRequest'
          description: Missing or invalid lat/lng parameters
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
          description: No buoy found within max_distance
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
      security:
        - ApiKeyAuth: []
components:
  headers:
    XRateLimitLimit:
      schema:
        type: integer
        description: Maximum requests allowed per hour
        example: 1000
      description: Maximum requests allowed per hour
    XRateLimitRemaining:
      schema:
        type: integer
        description: Requests remaining in current hour
        example: 987
      description: Requests remaining in current hour
    XRateLimitReset:
      schema:
        type: integer
        description: Unix timestamp when rate limit resets
        example: 1735326000
      description: Unix timestamp when rate limit resets
  schemas:
    BuoyWithDistance:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        lat:
          type: number
          format: float
        lng:
          type: number
          format: float
        source:
          type: string
          description: Data source (e.g., "météo-france", "noaa")
        source_identifier:
          type: string
          description: Source-specific identifier
        distance_km:
          type: number
          format: float
          description: Distance from query coordinates in kilometers
        last_reading:
          type: object
          nullable: true
          properties:
            significient_height:
              type: number
              format: float
            period:
              type: number
              format: float
            time:
              type: string
              format: date-time
    ErrorResponse:
      type: object
      description: Standardized error response format for V2 API
      properties:
        error:
          type: string
          description: >-
            Error code (e.g., "unauthorized", "bad_request",
            "resource_not_found")
          example: unauthorized
        message:
          type: string
          description: Human-readable error message
          example: Invalid API key
        details:
          type: object
          description: Additional error details (optional, varies by error type)
  responses:
    BadRequest:
      description: Bad request (400 Bad Request)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: bad_request
            message: Search term must be at least 2 characters
            timestamp: '2025-12-27T14:30:00Z'
            request_id: 550e8400-e29b-41d4-a716-446655440000
    Unauthorized:
      description: Invalid or missing API key (401 Unauthorized)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: unauthorized
            message: Invalid API key
            timestamp: '2025-12-27T14:30:00Z'
            request_id: 550e8400-e29b-41d4-a716-446655440000
    NotFound:
      description: Resource not found (404 Not Found)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: resource_not_found
            message: Couldn't find Spot with 'id'=999
            timestamp: '2025-12-27T14:30:00Z'
            request_id: 550e8400-e29b-41d4-a716-446655440000
    RateLimitExceeded:
      description: Rate limit exceeded (429 Too Many Requests)
      headers:
        X-RateLimit-Limit:
          schema:
            type: integer
            description: Maximum requests allowed per hour
            example: 1000
        X-RateLimit-Remaining:
          schema:
            type: integer
            description: Requests remaining in current hour
            example: 0
        X-RateLimit-Reset:
          schema:
            type: integer
            description: Unix timestamp when rate limit resets (top of next hour)
            example: 1735326000
        Retry-After:
          schema:
            type: integer
            description: Seconds to wait before retrying
            example: 3600
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: rate_limit_exceeded
            message: You have exceeded 1000 requests per hour
            timestamp: '2025-12-27T14:30:00Z'
            request_id: 550e8400-e29b-41d4-a716-446655440000
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >
        API key authentication. Pass your API key as a Bearer token in the
        Authorization header.


        Format: `Authorization: Bearer YOUR_API_KEY`


        Alternative: Pass as query parameter `?api_key=YOUR_API_KEY`


        **Security:** API keys are stored as BCrypt hashes (never plain text).
        Only the hash is stored in the database.

````