Files and skills
Upload provider-hosted files and reusable Anthropic skills.
Swift AI includes focused clients for provider resources that live outside a model request.
Referencing an upload in a message
uploadFile works against any client conforming to FileUploadAPI and tags
the result with the provider, so the upload can be dropped straight into a
message:
let uploaded = try await uploadFile(
api: OpenAIFiles(),
data: pdf,
filename: "report.pdf",
mediaType: "application/pdf"
)
let answer = try await generateText(
model: OpenAIModel("gpt-5"),
messages: [Message(role: .user, content: [
.text("Summarize this."),
.file(uploaded.file(mediaType: "application/pdf"))
])]
)uploaded.file(mediaType:) and uploaded.image() build content parts whose
providerReference maps a provider name to its file id (["openai": "file_123"]). A provider that recognizes its own key sends the id — OpenAI as
file_id on an input_file / input_image, Anthropic as a file source —
and a provider that does not simply ignores the reference, so a reference
minted for one provider is never leaked to another.
OpenAI files
let files = OpenAIFiles() // OPENAI_API_KEY
let uploaded = try await files.upload(
data: pdf,
filename: "report.pdf",
purpose: "user_data",
mediaType: "application/pdf"
)
print(uploaded.id)
try await files.delete(id: uploaded.id)OpenAIFiles uses https://api.openai.com/v1 by default. The returned
UploadedFile contains the provider ID plus filename and size when available.
See the OpenAI provider page for model APIs.
Anthropic files
let uploaded = try await AnthropicFiles().upload(
data: pdf,
filename: "report.pdf",
mediaType: "application/pdf"
)AnthropicFiles reads ANTHROPIC_API_KEY and adds the required Files API beta
header. See the Anthropic provider page.
Anthropic skills
Upload a SKILL.md folder as reusable provider-hosted content:
let skill = try await AnthropicSkills().upload(
files: [
SkillFile(path: "brand-guide/SKILL.md", data: skillMarkdown),
SkillFile(path: "brand-guide/references/tone.md", data: toneGuide),
],
displayTitle: "Brand guide"
)
print(skill.id)Paths are preserved in the multipart upload. AnthropicSkills handles the
required Skills API beta header.