ipfrs-interface 0.1.0

HTTP, gRPC, GraphQL and Python interfaces for IPFRS distributed storage
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
openapi: 3.0.3
info:
  title: IPFRS HTTP Gateway API
  description: |
    High-performance IPFS-compatible HTTP Gateway and API for IPFRS.

    ## Features
    - Kubo-compatible v0 API endpoints
    - High-speed v1 API with batch operations
    - gRPC interface for advanced use cases
    - WebSocket support for real-time updates
    - Zero-copy tensor API for ML workloads

    ## Authentication
    Most endpoints support optional Bearer token authentication.
    Include the token in the Authorization header:
    ```
    Authorization: Bearer <your-token>
    ```
  version: 0.1.0
  contact:
    name: IPFRS Project
  license:
    name: MIT OR Apache-2.0

servers:
  - url: http://localhost:8080
    description: Local development server
  - url: https://gateway.ipfrs.io
    description: Production gateway

tags:
  - name: Kubo v0
    description: IPFS Kubo-compatible API endpoints
  - name: High-Speed v1
    description: Optimized high-performance API
  - name: Gateway
    description: HTTP gateway for content retrieval
  - name: Streaming
    description: Chunked upload/download endpoints
  - name: Tensor
    description: Zero-copy tensor operations
  - name: WebSocket
    description: Real-time WebSocket API
  - name: Admin
    description: Administrative endpoints

paths:
  # Gateway endpoints
  /ipfs/{cid}:
    get:
      summary: Get content by CID
      description: Retrieve content via the IPFS HTTP gateway
      tags: [Gateway]
      parameters:
        - name: cid
          in: path
          required: true
          schema:
            type: string
          description: Content Identifier (CID)
          example: QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
        - name: Range
          in: header
          required: false
          schema:
            type: string
          description: Byte range for partial content
          example: bytes=0-1023
      responses:
        '200':
          description: Content retrieved successfully
          headers:
            Content-Type:
              schema:
                type: string
              description: MIME type of content
            ETag:
              schema:
                type: string
              description: CID-based ETag for caching
            Cache-Control:
              schema:
                type: string
              description: Caching directives
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '206':
          description: Partial content (range request)
          headers:
            Content-Range:
              schema:
                type: string
              example: bytes 0-1023/2048
        '304':
          description: Not Modified (cached content is still valid)
        '400':
          description: Invalid CID format
        '404':
          description: Content not found
        '416':
          description: Range not satisfiable

  /health:
    get:
      summary: Health check
      description: Check if the server is running
      tags: [Admin]
      responses:
        '200':
          description: Server is healthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok

  # Kubo v0 API
  /api/v0/add:
    post:
      summary: Add file
      description: Upload a file to IPFS
      tags: [Kubo v0]
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '200':
          description: File added successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  Hash:
                    type: string
                    description: CID of the added file
                  Size:
                    type: integer
                    description: Size in bytes

  /api/v0/cat:
    post:
      summary: Cat file
      description: Download a file from IPFS
      tags: [Kubo v0]
      parameters:
        - name: arg
          in: query
          required: true
          schema:
            type: string
          description: CID of the file to retrieve
      responses:
        '200':
          description: File content
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

  /api/v0/block/get:
    post:
      summary: Get block
      description: Retrieve a raw IPFS block
      tags: [Kubo v0]
      parameters:
        - name: arg
          in: query
          required: true
          schema:
            type: string
          description: CID of the block
      responses:
        '200':
          description: Raw block data
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

  /api/v0/block/put:
    post:
      summary: Put block
      description: Store a raw IPFS block
      tags: [Kubo v0]
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                block:
                  type: string
                  format: binary
      responses:
        '200':
          description: Block stored successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  Hash:
                    type: string
                  Size:
                    type: integer

  /api/v0/dag/get:
    post:
      summary: Get DAG node
      description: Retrieve a DAG node with optional path
      tags: [Kubo v0]
      parameters:
        - name: arg
          in: query
          required: true
          schema:
            type: string
          description: CID and optional path
      responses:
        '200':
          description: DAG node data
          content:
            application/json:
              schema:
                type: object

  /api/v0/dag/put:
    post:
      summary: Put DAG node
      description: Store a DAG node
      tags: [Kubo v0]
      requestBody:
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: DAG node stored
          content:
            application/json:
              schema:
                type: object
                properties:
                  Cid:
                    type: object
                    properties:
                      '/':
                        type: string

  /api/v0/id:
    post:
      summary: Node identity
      description: Get node identity information
      tags: [Kubo v0]
      responses:
        '200':
          description: Node identity
          content:
            application/json:
              schema:
                type: object
                properties:
                  ID:
                    type: string
                  PublicKey:
                    type: string
                  Addresses:
                    type: array
                    items:
                      type: string
                  AgentVersion:
                    type: string
                  ProtocolVersion:
                    type: string

  /api/v0/version:
    post:
      summary: Version info
      description: Get IPFS version information
      tags: [Kubo v0]
      responses:
        '200':
          description: Version information
          content:
            application/json:
              schema:
                type: object
                properties:
                  Version:
                    type: string
                  Commit:
                    type: string
                  System:
                    type: string
                  Golang:
                    type: string

  /api/v0/swarm/peers:
    post:
      summary: List peers
      description: Get list of connected peers
      tags: [Kubo v0]
      responses:
        '200':
          description: Peer list
          content:
            application/json:
              schema:
                type: object
                properties:
                  Peers:
                    type: array
                    items:
                      type: object
                      properties:
                        Peer:
                          type: string
                        Addr:
                          type: string

  /api/v0/stats/bw:
    post:
      summary: Bandwidth stats
      description: Get bandwidth statistics
      tags: [Kubo v0]
      responses:
        '200':
          description: Bandwidth statistics
          content:
            application/json:
              schema:
                type: object
                properties:
                  TotalIn:
                    type: integer
                  TotalOut:
                    type: integer
                  RateIn:
                    type: number
                  RateOut:
                    type: number

  /api/v0/pin/add:
    post:
      summary: Pin content
      description: Pin content to keep it cached
      tags: [Kubo v0]
      parameters:
        - name: arg
          in: query
          required: true
          schema:
            type: string
          description: CID to pin
      responses:
        '200':
          description: Content pinned
          content:
            application/json:
              schema:
                type: object
                properties:
                  Pins:
                    type: array
                    items:
                      type: string

  # High-speed v1 API
  /v1/stream/upload:
    post:
      summary: Streaming upload
      description: Upload large files with chunking and progress tracking
      tags: [Streaming]
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
      responses:
        '200':
          description: Upload complete
          content:
            application/json:
              schema:
                type: object
                properties:
                  cid:
                    type: string
                  size:
                    type: integer
                  chunks_received:
                    type: integer

  /v1/stream/download/{cid}:
    get:
      summary: Streaming download
      description: Download content with chunked streaming
      tags: [Streaming]
      parameters:
        - name: cid
          in: path
          required: true
          schema:
            type: string
        - name: chunk_size
          in: query
          schema:
            type: integer
            default: 65536
          description: Chunk size in bytes
      responses:
        '200':
          description: Content stream
          headers:
            X-Chunk-Size:
              schema:
                type: integer
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

  /v1/progress/{operation_id}:
    get:
      summary: Progress updates
      description: Server-Sent Events stream for operation progress
      tags: [Streaming]
      parameters:
        - name: operation_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: SSE stream
          content:
            text/event-stream:
              schema:
                type: object
                properties:
                  event:
                    type: string
                  data:
                    type: object

  /v1/block/batch/get:
    post:
      summary: Batch get blocks
      description: Retrieve multiple blocks in parallel
      tags: [High-Speed v1]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                cids:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Blocks retrieved
          content:
            application/json:
              schema:
                type: object
                properties:
                  blocks:
                    type: array
                    items:
                      type: object
                      properties:
                        cid:
                          type: string
                        data:
                          type: string
                          format: byte

  /v1/block/batch/put:
    post:
      summary: Batch put blocks
      description: Store multiple blocks in a single transaction
      tags: [High-Speed v1]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                blocks:
                  type: array
                  items:
                    type: object
                    properties:
                      data:
                        type: string
                        format: byte
                transaction_mode:
                  type: string
                  enum: [atomic, best_effort]
                  default: best_effort
      responses:
        '200':
          description: Blocks stored
          content:
            application/json:
              schema:
                type: object
                properties:
                  cids:
                    type: array
                    items:
                      type: string
                  transaction_id:
                    type: string

  /v1/block/batch/has:
    post:
      summary: Batch check blocks
      description: Check existence of multiple blocks
      tags: [High-Speed v1]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                cids:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Existence results
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        cid:
                          type: string
                        exists:
                          type: boolean

  # Tensor API
  /v1/tensor/{cid}:
    get:
      summary: Get tensor
      description: Zero-copy tensor retrieval with optional slicing
      tags: [Tensor]
      parameters:
        - name: cid
          in: path
          required: true
          schema:
            type: string
        - name: slice
          in: query
          required: false
          schema:
            type: string
          description: Tensor slice specification (e.g., "0:10,5:15")
      responses:
        '200':
          description: Tensor data
          headers:
            X-Tensor-Shape:
              schema:
                type: string
              example: "[100, 50]"
            X-Tensor-Dtype:
              schema:
                type: string
              example: F32
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary

  /v1/tensor/{cid}/info:
    get:
      summary: Get tensor metadata
      description: Retrieve only tensor metadata without data
      tags: [Tensor]
      parameters:
        - name: cid
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Tensor metadata
          content:
            application/json:
              schema:
                type: object
                properties:
                  shape:
                    type: array
                    items:
                      type: integer
                  dtype:
                    type: string
                  size:
                    type: integer
                  layout:
                    type: string
                    enum: [RowMajor, ColumnMajor]

  # WebSocket
  /ws:
    get:
      summary: WebSocket connection
      description: Upgrade to WebSocket for real-time updates
      tags: [WebSocket]
      responses:
        '101':
          description: Switching Protocols

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token obtained from /api/v0/auth/login
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key for service-to-service authentication

  schemas:
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Error message
          example: "Content not found"
        code:
          type: string
          description: Error code
          example: "NOT_FOUND"
        request_id:
          type: string
          description: Unique request identifier for debugging
          example: "550e8400-e29b-41d4-a716-446655440000"

    LoginRequest:
      type: object
      required:
        - username
        - password
      properties:
        username:
          type: string
          example: "alice"
        password:
          type: string
          format: password
          example: "secret123"

    LoginResponse:
      type: object
      properties:
        token:
          type: string
          description: JWT access token
          example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
        expires_in:
          type: integer
          description: Token expiration time in seconds
          example: 86400

    RegisterRequest:
      type: object
      required:
        - username
        - password
      properties:
        username:
          type: string
          minLength: 3
          maxLength: 50
          example: "alice"
        password:
          type: string
          format: password
          minLength: 8
          example: "secret123"

    BlockInfo:
      type: object
      properties:
        cid:
          type: string
          description: Content Identifier
          example: "QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco"
        size:
          type: integer
          description: Block size in bytes
          example: 1234
        data:
          type: string
          format: byte
          description: Base64-encoded block data

    BatchGetRequest:
      type: object
      required:
        - cids
      properties:
        cids:
          type: array
          items:
            type: string
          minItems: 1
          maxItems: 1000
          example: ["QmXoyp...", "QmYabcd..."]

    BatchGetResponse:
      type: object
      properties:
        blocks:
          type: array
          items:
            $ref: '#/components/schemas/BlockInfo'
        errors:
          type: array
          items:
            type: object
            properties:
              cid:
                type: string
              error:
                type: string

    BatchPutRequest:
      type: object
      required:
        - blocks
      properties:
        blocks:
          type: array
          items:
            type: object
            required:
              - data
            properties:
              data:
                type: string
                format: byte
                description: Base64-encoded block data
          minItems: 1
          maxItems: 1000
        transaction_mode:
          type: string
          enum: [atomic, best_effort]
          default: best_effort
          description: |
            - atomic: All blocks succeed or all fail
            - best_effort: Continue on individual failures

    BatchPutResponse:
      type: object
      properties:
        cids:
          type: array
          items:
            type: string
          description: CIDs of successfully stored blocks
        transaction_id:
          type: string
          description: Transaction ID for atomic operations
          example: "550e8400-e29b-41d4-a716-446655440000"
        errors:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              error:
                type: string

    TensorMetadata:
      type: object
      properties:
        shape:
          type: array
          items:
            type: integer
          example: [100, 50]
        dtype:
          type: string
          enum: [F32, F64, I32, I64, U8, U16, U32, U64]
          example: "F32"
        size:
          type: integer
          description: Total size in bytes
          example: 20000
        layout:
          type: string
          enum: [RowMajor, ColumnMajor]
          default: RowMajor
        num_elements:
          type: integer
          description: Total number of tensor elements
          example: 5000

    ProgressEvent:
      type: object
      properties:
        operation_id:
          type: string
          format: uuid
          example: "550e8400-e29b-41d4-a716-446655440000"
        status:
          type: string
          enum: [started, in_progress, completed, failed]
        progress:
          type: number
          format: float
          minimum: 0
          maximum: 1
          description: Progress from 0.0 to 1.0
          example: 0.65
        bytes_processed:
          type: integer
          example: 65536
        total_bytes:
          type: integer
          example: 100000
        message:
          type: string
          example: "Uploading chunk 3 of 5"

security:
  - BearerAuth: []
  - ApiKeyAuth: []
  - {}