Every API here is available over the APIs.io API and to AI agents over MCP.
openapi: 3.2.0
info:
title: Foundry Files API
version: v1
description: 'One API for every listed model, priced and settled in USDF: 1 USDF = $1 of compute, redeemable 1:1 for USDG. Pay with an API key (Authorization: Bearer sk_..., or x-api-key on the Messages API), or per request with no account under /x402 (x402, or MPP). The account''s keys, withdrawals, settings and wallet take a signed-in session. With a key, a request places a hold for its most possible cost and is charged the provider''s reported usage at the published price (GET /v1/pricing); over x402 it pays that most possible cost, its quote, up front, is charged its usage at the same price and gets the rest back. Every answer carries its receipt, and every request is a leaf in the public usage log (GET /v1/log/proof/{request_id}). Amounts are USDF base units as decimal strings (1 unit = 0.000001 USDF). Errors are {error: {message, type, code}}, except on the Messages API, which answers in its own envelope. Rate limits: GET /v1/limits.'
servers:
- url: https://api.usdf.fi
tags:
- name: Files
description: 'Files uploaded once and named by id in chat, Responses and Messages requests: kept encrypted until deleted (or the account''s data is), never sent back, never in an export or a backup; a model''s host receives the content alone. The file-parser plugin reads a PDF as text here, at no charge.'
paths:
/v1/files:
post:
operationId: uploadFile
tags:
- Files
summary: Upload a file
description: 'multipart/form-data with the file in `file`. Kept encrypted, with a key of its own, until it is deleted; named by id in a request ({type: "file", file: {file_id}} in chat, input_file or input_image with file_id in Responses, a document or image source {type: "file", file_id} in Messages), whose content it then is, billed as if sent inline. A PDF, an image, text and MP3 or WAV audio are read into a request; FLAC, OGG and office documents are stored only. At most 32 MiB a file, 1 GiB and 1,000 files an account.'
security:
- messagesApiKey: []
- apiKey: []
requestBody:
required: true
description: multipart/form-data.
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/FileUploadRequest'
responses:
'200':
description: The stored file.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/File'
- $ref: '#/components/schemas/FileWithPurpose'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'413':
$ref: '#/components/responses/TooLarge'
'429':
$ref: '#/components/responses/RateLimited'
'503':
$ref: '#/components/responses/Unavailable'
default:
$ref: '#/components/responses/Error'
get:
operationId: listFiles
tags:
- Files
summary: List files
description: 'The files this key may read, oldest first: the account''s own keys and its session see every file of the account; a platform key, a sub-key or an org key the files it uploaded.'
security:
- messagesApiKey: []
- apiKey: []
parameters:
- name: limit
in: query
required: false
description: How many rows to return, at most 1000 (default 100).
schema:
type: integer
minimum: 1
maximum: 1000
- name: cursor
in: query
required: false
description: The cursor of the page before.
schema:
type: string
- name: after
in: query
required: false
description: 'A file id: the page just after it (after_id is the same).'
schema:
type: string
- name: after_id
in: query
required: false
description: 'A file id: the page just after it.'
schema:
type: string
- name: order
in: query
required: false
description: asc, the one order.
schema:
type: string
enum:
- asc
responses:
'200':
description: A page of files.
content:
application/json:
schema:
$ref: '#/components/schemas/FileList'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'429':
$ref: '#/components/responses/RateLimited'
'503':
$ref: '#/components/responses/Unavailable'
default:
$ref: '#/components/responses/Error'
/v1/files/{file_id}:
get:
operationId: getFile
tags:
- Files
summary: Read a file's metadata
description: One file this key may read; 404 for any other, as for one that does not exist.
security:
- messagesApiKey: []
- apiKey: []
parameters:
- name: file_id
in: path
required: true
description: The file's id.
schema:
type: string
example: file_7Qe2LwMRfY0hT3oPq9ZcV1bN
responses:
'200':
description: The file.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/File'
- $ref: '#/components/schemas/FileWithPurpose'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
'429':
$ref: '#/components/responses/RateLimited'
'503':
$ref: '#/components/responses/Unavailable'
default:
$ref: '#/components/responses/Error'
delete:
operationId: deleteFile
tags:
- Files
summary: Delete a file
description: The file, its key and every byte of it, deleted at once; 404 for a file this key may not read.
security:
- messagesApiKey: []
- apiKey: []
parameters:
- name: file_id
in: path
required: true
description: The file's id.
schema:
type: string
example: file_7Qe2LwMRfY0hT3oPq9ZcV1bN
responses:
'200':
description: Deleted.
content:
application/json:
schema:
$ref: '#/components/schemas/FileDeleted'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
'429':
$ref: '#/components/responses/RateLimited'
'503':
$ref: '#/components/responses/Unavailable'
default:
$ref: '#/components/responses/Error'
/v1/files/{file_id}/content:
get:
operationId: getFileContent
tags:
- Files
summary: A file's content
description: 'An uploaded file is never sent back: 400 file_not_downloadable for one this key may read, 404 for any other. Keep your own copy.'
security:
- messagesApiKey: []
- apiKey: []
parameters:
- name: file_id
in: path
required: true
description: The file's id.
schema:
type: string
example: file_7Qe2LwMRfY0hT3oPq9ZcV1bN
responses:
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
'429':
$ref: '#/components/responses/RateLimited'
default:
$ref: '#/components/responses/Error'
components:
schemas:
FileList:
type: object
description: A page of files, oldest first.
properties:
data:
type: array
items:
$ref: '#/components/schemas/File'
has_more:
type: boolean
first_id:
anyOf:
- type: string
- type: 'null'
last_id:
anyOf:
- type: string
- type: 'null'
cursor:
anyOf:
- type: string
description: 'The next page''s cursor; null on the last page. Absent with the Messages API''s version header; the purpose shape has object: list in its place.'
- type: 'null'
required:
- data
- has_more
- first_id
- last_id
FileUploadRequest:
type: object
properties:
file:
type: string
description: 'The file: at most 32 MiB here; its type is read from its content.'
format: binary
purpose:
type: string
description: The purpose, kept and shown in the shape with object and bytes; user_data when not given.
enum:
- assistants
- batch
- fine-tune
- vision
- user_data
- evals
required:
- file
FileDeleted:
type: object
description: 'The file is deleted: its key and every byte of it.'
properties:
id:
type: string
type:
type: string
enum:
- file_deleted
object:
type: string
description: 'The purpose shape: file.'
enum:
- file
deleted:
type: boolean
description: 'The purpose shape: true.'
required:
- id
FileWithPurpose:
type: object
description: 'A stored file in the shape with object, bytes and purpose: the answer to an upload with a purpose, or to a client of the chat API''s SDKs.'
properties:
id:
type: string
object:
type: string
enum:
- file
bytes:
type: integer
created_at:
type: integer
description: Unix seconds.
filename:
type: string
purpose:
type: string
enum:
- assistants
- batch
- fine-tune
- vision
- user_data
- evals
status:
type: string
enum:
- processed
required:
- id
- object
- bytes
- created_at
- filename
- purpose
- status
Error:
type: object
description: The error envelope of every endpoint but the Messages API. Some errors carry more fields beside `error` (a 402 from an x402 path carries the quote).
properties:
error:
type: object
properties:
message:
type: string
description: What went wrong, in words.
type:
type: string
description: 'The class of the error: invalid_request_error, authentication_error, insufficient_quota, permission_error, rate_limit_error, payment_required, upstream_error, service_unavailable, server_error.'
code:
anyOf:
- type: string
- type: integer
- type: 'null'
description: 'A stable code for the error, or null. In the router API''s envelope (where it is on: an API key on the router API''s paths, outside the site): the HTTP status as an integer, the stable code then in metadata.error_code.'
param:
anyOf:
- type: string
description: The request field at fault, where the error names one.
- type: 'null'
metadata:
type: object
description: Present on a 429, on a budget's refusal and on every error in the router API's envelope.
properties:
error_type:
type: string
description: rate_limit_exceeded on every 429; in the router API's envelope, its category of every error (invalid_request, authentication, payment_required, permission_denied, not_found, rate_limit_exceeded, provider_unavailable, timeout, server and the others it lists).
error_code:
anyOf:
- type: string
description: 'In the router API''s envelope: the stable code (what code is in the other envelope).'
- type: 'null'
scope:
type: string
description: 'In the router API''s envelope, on a budget''s refusal: key_limit.'
provider_code:
type: string
description: 'In the router API''s envelope, on a stream''s failure: the provider''s own status, where it gave one.'
limit_source:
type: string
description: 'On a budget''s refusal (402): key_limit for the key''s budgets, key_spend_limit for its trailing caps.'
reset_interval:
anyOf:
- type: string
description: 'The interval a budget starts again on, at 00:00 UTC: a day, a week from Monday or a month; null for a lifetime budget or a trailing cap.'
- type: 'null'
resets_at:
type: string
description: When the budget starts again (ISO 8601).
window:
type: string
description: 'A trailing cap''s span: 1h, 24h or 30d.'
required:
- message
- type
required:
- error
File:
type: object
description: A stored file.
properties:
id:
type: string
description: 'The file''s id: file_ and 24 letters and digits.'
pattern: ^file_[0-9A-Za-z]{24}$
example: file_7Qe2LwMRfY0hT3oPq9ZcV1bN
type:
type: string
enum:
- file
filename:
type: string
description: The name it was uploaded with (a / makes folders).
mime_type:
type: string
description: 'The type read from the content: application/pdf, image/png, image/jpeg, image/gif, image/webp, audio/mpeg, audio/wav, audio/flac, audio/ogg, the three office documents, or text as application/json, application/x-ndjson, text/csv, text/markdown or text/plain.'
size_bytes:
type: integer
description: Its size.
created_at:
type: string
description: When it was uploaded (RFC 3339).
format: date-time
downloadable:
type: boolean
description: 'Always false: an uploaded file is never sent back.'
required:
- id
- type
- filename
- mime_type
- size_bytes
- created_at
- downloadable
responses:
Forbidden:
description: 'The credentials are valid but may not do this (a key where a session is required, a key''s model list, a key used from an address off its IP allowlist: ip_not_allowed, another account''s object). A money or credential action with a session whose sign-in is older than its window is reauth_required (max_age_seconds: 300 for money leaving the account, 900 for keys, the wallet and the like): confirm it''s you (GET /v1/session/confirm) or sign in again, and send it once more. recent_link_hold: a sign-in method was added in the last 24 hours, so money and keys leave the account only from lifts_at, or now once this session confirms with a method it had before. API keys are never asked.'
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Unauthorized:
description: 'No credentials, or credentials that are unknown, revoked, past their expiry (key_expired) or signed out. error.code says which: missing_api_key (a read that takes an API key or a signed-in session was sent neither), invalid_api_key (a route that takes an API key was sent none, or one the ledger rejects; on a read that takes an API key or a signed-in session, a credential that is neither), unauthenticated (a route that takes a signed-in session was sent none, or one that expired).'
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
NotFound:
description: No such object for these credentials, or a model that is not listed.
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
RateLimited:
description: Over a rate limit; retry after the number of seconds in retry-after (GET /v1/limits lists every limit).
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
retry-after:
$ref: '#/components/headers/retry-after'
x-ratelimit-limit:
$ref: '#/components/headers/x-ratelimit-limit'
x-ratelimit-remaining:
$ref: '#/components/headers/x-ratelimit-remaining'
x-ratelimit-reset:
$ref: '#/components/headers/x-ratelimit-reset'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
BadRequest:
description: The request is malformed or asks for something this endpoint refuses; nothing was charged.
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
TooLarge:
description: The request body is over this endpoint's size limit.
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Error:
description: An error.
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Unavailable:
description: 'The feature or a dependency is unavailable on this gateway right now, or none of a model''s zero-retention routes can take the request now while it has one (zero_retention_unavailable: a request for such a model is served on those alone); retry after retry-after where it is sent.'
headers:
x-request-id:
$ref: '#/components/headers/x-request-id'
retry-after:
$ref: '#/components/headers/retry-after'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
headers:
x-ratelimit-limit:
description: 'On a 429: the refusing limit, in requests per its window (0 where the refusal is not a count of requests).'
schema:
type: string
x-ratelimit-reset:
description: 'On a 429: when a request is let through again, in milliseconds since the epoch.'
schema:
type: string
x-request-id:
description: The request's id (its receipt's request_id). Every error answer, 4xx and 5xx, carries one too.
schema:
type: string
x-ratelimit-remaining:
description: 'On a 429: what is left of it (0).'
schema:
type: string
retry-after:
description: Seconds to wait before retrying.
schema:
type: string
securitySchemes:
apiKey:
type: http
scheme: bearer
bearerFormat: sk_...
description: 'An API key, as Authorization: Bearer sk_.... A key spends from the balance of the account it was made under (or its own budget), within its limits. Create keys with POST /v1/account/keys under a signed-in session.'
messagesApiKey:
type: apiKey
in: header
name: x-api-key
description: 'The same API key in the x-api-key header, as the Messages API''s clients send it. Authorization: Bearer sk_... is accepted on the Messages API as well.'
session:
type: http
scheme: bearer
bearerFormat: JWT
description: 'A signed-in session: the access token from signing in at usdf.fi, as Authorization: Bearer <token>. GET /v1/auth names the issuer, the app id and the key set it is checked against; POST /v1/session links a sign-in to its account. The account''s keys, withdrawals, settings and wallet, and sending, claiming or cancelling a link, take a session, not an API key.'
x402:
type: apiKey
in: header
name: payment-signature
description: 'Pay per request with x402, no account. A request without payment is answered 402 with the payment requirements (the payment-required header, and in the body as `x402`) and the quote: the most the request can cost. Pay in USDF (a signature transfer, after a one-time approval of USDF to the signature-transfer contract) or USDG (a signed transferWithAuthorization), and send the same request again with the signed payment in payment-signature. The payment is the quote. A model request whose bound is below the minimum charge (the gas of returning a payment at the chain''s gas price now, with a margin, rounded up) is quoted that minimum instead (the quote''s minimum_charge, with floored true) and charged it whole. The paid answer carries payment-response; a request quoted above the minimum is charged what it used at that price, never more than the payment, the rest refunded in the asset paid (the receipt''s paid and refund) unless it is smaller than the gas of returning it, which is kept. A request that fails once paid is refunded in full, in the asset paid. Apart from the minimum charge, a request is charged at most its list price, never below cost. Every model is priced at or below its list price.'
mpp:
type: http
scheme: Payment
description: 'The same payment as an MPP credential: where MPP is on (GET /v1/reserve lists it per chain), a 402 from an x402 path also carries Payment challenges in WWW-Authenticate (method evm, intent charge, in USDG by a signed transfer authorization or USDF by signature transfer); the retry carries Authorization: Payment <credential>. A paid answer carries Payment-Receipt.'
nodeCredential:
type: http
scheme: bearer
bearerFormat: nk_...
description: 'A node credential, as Authorization: Bearer nk_...: what a machine receives once its owner approves it (POST /v1/network/device, then POST /v1/network/device/token). It registers and runs that one node, with the payout address and terms its owner approved, and reads that node''s own figures and earnings; it claims nothing, spends nothing and is taken nowhere else. Removing the node revokes it.'
videoReadToken:
type: http
scheme: bearer
bearerFormat: vtk_...
description: 'The read token of a video job paid with x402, from its 202 answer, as Authorization: Bearer vtk_.... It is shown only once, and the job cannot be read without it.'