← API Reference

Language Guide · Swift

Manage AI Prompts in Swift

No SDK required. One HTTP call.

Fetch versioned, variable-interpolated AI prompts from Swift using URLSession. Works with iOS, macOS, watchOS, tvOS, visionOS, and server-side Swift with Vapor.

Code Example

One function. Any AI provider.

Fetch a versioned, interpolated prompt from PromptForge with a single HTTP call. The returned content string passes directly to your AI SDK — no transformation, no adapter, no extra library.

  1. 1Fetch a versioned prompt by ID with your variable values.
  2. 2Receive the fully rendered content string in the response.
  3. 3Pass it directly to your AI provider SDK as the system prompt.
promptforge.swift
Swift
import Foundation

struct PromptResponse: Decodable {
    let content: String
}

func fetchPrompt(
    apiKey: String,
    promptID: String,
    variables: [String: String] = [:]
) async throws -> String {
    var components        = URLComponents(string: "https://www.promptforge-app.com/api/v1/prompts/\(promptID)")!
    var queryItems        = [URLQueryItem(name: "_version", value: "latest")]
    queryItems           += variables.map { URLQueryItem(name: $0.key, value: $0.value) }
    components.queryItems = queryItems

    var request = URLRequest(url: components.url!)
    request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")

    let (data, _) = try await URLSession.shared.data(for: request)
    return try JSONDecoder().decode(PromptResponse.self, from: data).content
}

Why Swift teams choose PromptForge

Designed for developers who want control without complexity.

Native async/await with Swift concurrency

URLSession.shared.data(for:) uses Swift's structured concurrency model — no Combine pipelines, no callbacks, no escaping closures.

Works on every Apple platform

The same URLSession code runs on iOS, macOS, watchOS, tvOS, visionOS, and server-side Vapor apps without any conditional compilation.

No third-party dependencies

Foundation is part of every Apple SDK target. No Package.swift dependency to add, no SPM resolution to run.

Integrate in 4 steps

From zero to fetching your first versioned prompt in under 10 minutes. No framework setup, no SDK installation — just HTTP.

  1. 1

    Create a prompt with variables

    Open the dashboard, click New Prompt, and write your system prompt using {{variable}} placeholders for any dynamic values.

  2. 2

    Copy your prompt ID

    Your prompt ID appears in the URL bar when editing: /dashboard/prompts/YOUR_PROMPT_ID. The API Usage panel also shows it with pre-filled examples.

  3. 3

    Generate an API key

    Go to the API settings page and click Generate Key. Store it in the iOS Keychain or as a server-side environment variable — never hard-code it.

  4. 4

    Fetch with URLSession

    Build a URLRequest with the Authorization header and call URLSession.shared.data(for:) in an async context. Decode with JSONDecoder and pass the content string to your AI provider.

Teams building AI features in Swift

iOS teams shipping AI-powered features use PromptForge to control system prompts from the dashboard without submitting App Store updates. Prompt changes are live on the next app launch — no review cycle, no TestFlight build, no user update required.

Start Free Trial
No SDK
required
1 call
to fetch any prompt
Instant
prompt updates
Any AI
provider supported

Start for free, upgrade anytime

No credit card required to get started. Paid plans include a 14-day free trial.

HobbyNo credit card
  • 1k API requests/month
  • 1 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start Managing My Prompts
Starter
14-day free trial
$9/month

No charge until your trial ends

  • 10k API requests/month
  • 5 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial
Most Popular
Pro
14-day free trial
$29/month

No charge until your trial ends

  • 100k API requests/month
  • 25 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial
Business
14-day free trial
$49/month

No charge until your trial ends

  • 500k API requests/month
  • 100 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial

Questions? Contact us