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

# Create Model

> ### Description

Creates and hosts a model based on a model template.

Base embedding models, chunk ranking functions, and LLMs are often not sufficient for customer use cases. We have shown in various blogs that fine-tuning these models on customer data can lead to significant improvements in performance.

1. [We Fine-Tuned GPT-4 to Beat the Industry Standard for Text2SQL]( https://scale.com/blog/text2sql-fine-tuning)
2. [OpenAI Names Scale as Preferred Partner to Fine-Tune GPT-3.5]( https://scale.com/blog/open-ai-scale-partnership-gpt-3-5-fine-tuning)
3. [How to Fine-Tune GPT-3.5 Turbo With OpenAI API]( https://scale.com/blog/fine-tune-gpt-3.5)
        

### Details

Before creating a model, you must first create a model template. A model template serves 2 purposes. First, it provides  common scaffolding that is static across multiple models. Second, it exposes several variables that can be injected at model creation time to customize the model.

For example, a model template can define a docker image that contains code to run a HuggingFace or SentenceTransformers model. This docker image code also accepts environment variables that can be set to swap out the model weights or model name. Refer to the Create Model Template API for more details.

To create a new model, users must refer to an existing model template and provide the necessary parameters the the model template requires in its `model_creation_parameters_schema` field. The combination of the model template and the model creation parameters will be used to create and deploy a new model.

Once a model has been created, it can be executed by calling the Execute Model API.
        


### Coming Soon
Some of our EGP APIs depend on models, for example Knowledge Base APIs depend on embedding models, Chunk Ranking APIs depend on ranking models, and Completion APIs depend on LLMs.

In the near future, if a model is created from a model template that is compatible with one of these APIs (based on the model template's `model_type field`), the model will automatically be registered with the API. This will allow users to immediately start using the model with those API without any additional setup.



## OpenAPI

````yaml https://app.stainlessapi.com/api/spec/documented/sgp/openapi.yml post /v4/models
openapi: 3.1.0
info:
  title: EGP API V4
  description: >-
    This is the parent API for all EGP APIs. If you are looking for the EGP API,
    please go to https://api.egp.scale.com/docs.
  contact:
    name: Scale Generative AI Platform
    url: https://scale.com/genai-platform
  version: 0.1.0
servers:
  - url: https://api.egp.scale.com
security: []
tags:
  - name: Models
    description: Model API.
paths:
  /v4/models:
    post:
      tags:
        - Models
      summary: Create Model
      description: >-
        ### Description


        Creates and hosts a model based on a model template.


        Base embedding models, chunk ranking functions, and LLMs are often not
        sufficient for customer use cases. We have shown in various blogs that
        fine-tuning these models on customer data can lead to significant
        improvements in performance.


        1. [We Fine-Tuned GPT-4 to Beat the Industry Standard for Text2SQL](
        https://scale.com/blog/text2sql-fine-tuning)

        2. [OpenAI Names Scale as Preferred Partner to Fine-Tune GPT-3.5](
        https://scale.com/blog/open-ai-scale-partnership-gpt-3-5-fine-tuning)

        3. [How to Fine-Tune GPT-3.5 Turbo With OpenAI API](
        https://scale.com/blog/fine-tune-gpt-3.5)
                

        ### Details


        Before creating a model, you must first create a model template. A model
        template serves 2 purposes. First, it provides  common scaffolding that
        is static across multiple models. Second, it exposes several variables
        that can be injected at model creation time to customize the model.


        For example, a model template can define a docker image that contains
        code to run a HuggingFace or SentenceTransformers model. This docker
        image code also accepts environment variables that can be set to swap
        out the model weights or model name. Refer to the Create Model Template
        API for more details.


        To create a new model, users must refer to an existing model template
        and provide the necessary parameters the the model template requires in
        its `model_creation_parameters_schema` field. The combination of the
        model template and the model creation parameters will be used to create
        and deploy a new model.


        Once a model has been created, it can be executed by calling the Execute
        Model API.
                


        ### Coming Soon

        Some of our EGP APIs depend on models, for example Knowledge Base APIs
        depend on embedding models, Chunk Ranking APIs depend on ranking models,
        and Completion APIs depend on LLMs.


        In the near future, if a model is created from a model template that is
        compatible with one of these APIs (based on the model template's
        `model_type field`), the model will automatically be registered with the
        API. This will allow users to immediately start using the model with
        those API without any additional setup.
      operationId: POST-V4-/models
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModelInstanceRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModelInstanceResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from scale_gp import SGPClient

            client = SGPClient(
                api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
            )
            model_instance = client.models.create(
                account_id="account_id",
                model_type="COMPLETION",
                name="name",
            )
            print(model_instance.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/sgp-go\"\n\t\"github.com/stainless-sdks/sgp-go/option\"\n)\n\nfunc main() {\n\tclient := sgp.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tmodelInstance, err := client.Models.New(context.TODO(), sgp.ModelNewParams{\n\t\tAccountID: sgp.F(\"account_id\"),\n\t\tModelType: sgp.F(sgp.ModelNewParamsModelTypeCompletion),\n\t\tName:      sgp.F(\"name\"),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", modelInstance.ID)\n}\n"
components:
  schemas:
    ModelInstanceRequest:
      properties:
        name:
          type: string
          title: Name
        display_name:
          title: Display Name
          type: string
        model_vendor:
          $ref: '#/components/schemas/ModelVendor'
        model_type:
          $ref: '#/components/schemas/ModelType'
        base_model_id:
          title: Base Model Id
          type: string
        base_model_metadata:
          $ref: '#/components/schemas/BaseModelMetadata'
        model_creation_parameters:
          title: Model Creation Parameters
          additionalProperties: true
          type: object
        model_card:
          title: Model Card
          type: string
        training_data_card:
          title: Training Data Card
          type: string
        description:
          title: Description
          type: string
        model_template_id:
          title: Model Template Id
          type: string
        model_group_id:
          title: Model Group Id
          type: string
        account_id:
          type: string
          title: Account Id
          description: The ID of the account that owns the given entity.
          can_patch: false
      type: object
      required:
        - name
        - model_type
        - account_id
      title: ModelInstanceRequest
    ModelInstanceResponse:
      properties:
        name:
          type: string
          title: Name
        display_name:
          title: Display Name
          type: string
        model_vendor:
          $ref: '#/components/schemas/ModelVendor'
        model_type:
          $ref: '#/components/schemas/ModelType'
        base_model_id:
          title: Base Model Id
          type: string
        base_model_metadata:
          $ref: '#/components/schemas/BaseModelMetadata'
        model_creation_parameters:
          title: Model Creation Parameters
          additionalProperties: true
          type: object
        model_card:
          title: Model Card
          type: string
        training_data_card:
          title: Training Data Card
          type: string
        description:
          title: Description
          type: string
        model_template_id:
          title: Model Template Id
          type: string
        model_group_id:
          title: Model Group Id
          type: string
        id:
          type: string
          title: Id
          description: The unique identifier of the entity.
        created_at:
          type: string
          format: date-time
          title: Created At
          description: The date and time when the entity was created in ISO format.
        account_id:
          type: string
          title: Account Id
          description: The ID of the account that owns the given entity.
          can_patch: false
        created_by_user_id:
          type: string
          title: Created By User Id
          description: The user who originally created the entity.
        created_by_identity_type:
          $ref: '#/components/schemas/IdentifierTypeEnum'
          description: The type of identity that created the entity.
        request_schema:
          additionalProperties: true
          type: object
          title: Request Schema
          description: JSON schema for the requests to the model instance
        response_schema:
          additionalProperties: true
          type: object
          title: Response Schema
          description: JSON schema for the response to the model
        deployment_count:
          type: integer
          title: Deployment Count
          description: Number of deployments of this model instance
        supports_multi_turn:
          type: boolean
          title: Supports Multi Turn
          description: True if a model supports multi-turn conversations natively
      type: object
      required:
        - name
        - model_type
        - id
        - created_at
        - account_id
        - created_by_user_id
        - created_by_identity_type
        - request_schema
        - response_schema
        - deployment_count
        - supports_multi_turn
      title: ModelInstanceResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ModelVendor:
      type: string
      enum:
        - OPENAI
        - COHERE
        - GOOGLE
        - VERTEX_AI
        - ANTHROPIC
        - LAUNCH
        - LLMENGINE
        - BEDROCK
        - FIREWORKS_AI
        - OTHER
      title: ModelVendor
      description: |-
        An enum representing the different types of model vendors supported.

        Attributes:
            OPENAI: Denotes that the model vendor is OpenAI.
            COHERE: Denotes that the model vendor is Cohere.
            GOOGLE: Denotes that the model vendor is Google.
            ANTHROPIC: Denotes that the model vendor is Anthropic.
            LLMENGINE: Denotes that the model vendor is LLM Engine.
            OTHER: Denotes that the model vendor is Other.
    ModelType:
      type: string
      enum:
        - COMPLETION
        - CHAT_COMPLETION
        - AGENT
        - EMBEDDING
        - RERANKING
        - GENERIC
        - BUNDLE
      title: ModelType
      description: |-
        An enum representing the different types of models supported.

        Attributes:
            COMPLETION: Denotes that the model type is completion.
            CHAT_COMPLETION: Denotes that the model type is chat completion.
            AGENT: Denotes that the model type is agent.
            EMBEDDING: Denotes that the model type is embedding.
            RERANKING: Denotes that the model type is reranking.
            GENERIC: Denotes that the model type is generic.
            BUNDLE: "Not to be used directly - type to surface a model bundle in the UI - TODO: Explicitly type a bundle
    BaseModelMetadata:
      properties:
        ui_model_section_type:
          $ref: '#/components/schemas/UiModelSectionType'
        model_developer:
          title: Model Developer
          type: string
        model_license_url:
          title: Model License Url
          type: string
        delivery_date:
          title: Delivery Date
          type: string
        modelDetails:
          $ref: '#/components/schemas/BaseModelDetails'
      type: object
      title: BaseModelMetadata
    IdentifierTypeEnum:
      type: string
      enum:
        - user
        - service_account
      title: IdentifierTypeEnum
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
          additionalProperties: true
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    UiModelSectionType:
      type: string
      enum:
        - PARTNER
        - OPENSOURCE
        - CUSTOM
      title: UiModelSectionType
    BaseModelDetails:
      properties:
        number_of_parameters:
          title: Number Of Parameters
          type: integer
        token_context_window:
          title: Token Context Window
          type: integer
        languages:
          title: Languages
          type: integer
        alignments:
          title: Alignments
          type: integer
      type: object
      title: BaseModelDetails

````