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

# Create Service

> Create or update a service definition.



## OpenAPI

````yaml /sprites/api/openapi.json put /v1/sprites/{name}/services/{service_name}
openapi: 3.1.0
info:
  title: Sprites API
  version: 0.1.12
  x-sprite-env-version: v0.0.1-rc48
servers:
  - url: https://api.sprites.dev
security: []
paths:
  /v1/sprites/{name}/services/{service_name}:
    put:
      tags:
        - Services
      summary: Create Service
      description: Create or update a service definition.
      operationId: sprite_env_create__service
      parameters:
        - in: path
          name: name
          required: true
          schema:
            type: string
        - in: path
          name: service_name
          required: true
          schema:
            type: string
        - description: 'Time to monitor logs after starting (default: `5s`)'
          in: query
          name: duration
          required: false
          schema:
            description: 'Time to monitor logs after starting (default: `5s`)'
            type: integer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ServiceRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              example:
                args:
                  - '-m'
                  - http.server
                  - '8000'
                cmd: python
                http_port: 8000
                name: webapp
                needs:
                  - postgres
                state:
                  name: webapp
                  started_at: '2026-01-05T10:30:00Z'
                  status: starting
              schema:
                $ref: '#/components/schemas/ServiceResponse'
          description: Success
        '400':
          description: Bad Request - Invalid request body
        '404':
          description: Not Found - Resource not found
        '500':
          description: Internal Server Error
      security:
        - bearerAuth: []
components:
  schemas:
    ServiceRequest:
      example:
        args:
          - '-m'
          - http.server
          - '8000'
        cmd: python
        http_port: 8000
        needs:
          - postgres
      properties:
        args:
          description: Command arguments
          items:
            type: string
          type: array
        cmd:
          description: Command to execute
          type: string
        dir:
          description: Working directory for the service
          type: string
        env:
          description: Environment variables to add to the base service environment
          type: object
        http_port:
          description: HTTP port for proxy routing
          type:
            - integer
            - 'null'
        needs:
          description: Service dependencies (started first)
          items:
            type: string
          type: array
      required:
        - cmd
        - args
        - needs
      type: object
    ServiceResponse:
      example:
        args:
          - '-m'
          - http.server
          - '8000'
        cmd: python
        http_port: 8000
        name: webapp
        needs:
          - postgres
        state:
          name: webapp
          pid: 1567
          started_at: '2026-01-05T08:01:00Z'
          status: running
      properties:
        args:
          description: Command arguments
          items:
            type: string
          type: array
        cmd:
          description: Command to execute
          type: string
        http_port:
          description: HTTP port for proxy routing
          type:
            - integer
            - 'null'
        name:
          description: Service name
          type: string
        needs:
          description: Service dependencies
          items:
            type: string
          type: array
        state:
          description: Current runtime state
          oneOf:
            - $ref: '#/components/schemas/ServiceState'
            - type: 'null'
      required:
        - name
        - cmd
        - args
        - needs
      type: object
    ServiceState:
      example:
        name: webapp
        pid: 1567
        started_at: '2026-01-05T08:01:00Z'
        status: running
      properties:
        error:
          description: Error message if failed
          type: string
        name:
          description: Service name
          type: string
        pid:
          description: Process ID when running
          type: integer
        started_at:
          description: ISO 8601 timestamp
          type: string
        status:
          description: '`stopped`, `starting`, `running`, `stopping`, or `failed`'
          type: string
      required:
        - name
        - status
      type: object
  securitySchemes:
    bearerAuth:
      scheme: bearer
      type: http

````